【发布时间】:2020-12-21 03:49:26
【问题描述】:
我一直在尝试为我正在制作的游戏添加一些音乐。我一直在尝试使用 winsound,因为它可以让您在播放中途停止声音。问题是 winsound 似乎无法找到我的声音文件。
我尝试过使用不同的模块,例如 playsound 模块,它能够很好地播放我的音乐,但 winsound 由于某种原因不能。不幸的是,我不能只为我的游戏使用 playsound 模块,因为它没有提供在游戏中途停止声音的方法。
这是我尝试过的:
#testing if winsound functions
import winsound
import playsound
#The file I want to play, test1.wav, is saved in the same folder as this file.
#Playing the sound using playsound, using a local directory
playsound.playsound('test1.wav')
#this works and plays the sound as intended
#Playing the sound using playsound, using a global directory
playsound.playsound(r'C:\Users\61490\Documents\Python\pano tiles\test1.wav')
#this also works and plays the sound as intended
#Playing the sound using winsound, using a local directory
winsound.PlaySound('test1.wav', winsound.SND_FILENAME)
#This only plays the windows default error sound
#Playing the sound using winsound, using a global directory
winsound.PlaySound(r'C:\Users\61490\Documents\Python\pano tiles\test1.wav', winsound.SND_FILENAME)
#This also only plays the windows default error sound
有人知道为什么会这样吗?
【问题讨论】:
标签: python windows audio winsound