报错信息:
Error 263 for command:
close audio.mp3
指定的设备未打开,或不被 MCI 所识别。
原因:
windows不支持utf-16编码,需修改playsound源码
playsound在:C:\Users\Megan\AppData\Local\Programs\Python\Python37\Lib\site-packages\playsound.py
解决:
修改两个地方:
代码:
def winCommand(*command):
bufLen = 600
buf = c_buffer(bufLen)
#command = ' '.join(command).encode('utf-16') # 1.修改前
command = ' '.join(command) # 1.修改后
errorCode = int(windll.winmm.mciSendStringW(command, buf, bufLen - 1, 0)) # use widestring version of the function
if errorCode:
errorBuffer = c_buffer(bufLen)
windll.winmm.mciGetErrorStringW(errorCode, errorBuffer, bufLen - 1) # use widestring version of the function
exceptionMessage = ('\n Error ' + str(errorCode) + ' for command:'
#'\n ' + command.decode('utf-16') + # 2.修改前
'\n ' + command + # 2.修改后
'\n ' + errorBuffer.raw.decode('utf-16').rstrip('\0'))
logger.error(exceptionMessage)
raise PlaysoundException(exceptionMessage)
return buf.value