Python 不使用Pygame模块播放音频
我想用pygame模块播放音频,但它不适合我。当我运行下面的代码时,它只会在不到一秒钟的时间内给出此消息,没有任何错误:Python 不使用Pygame模块播放音频,python,audio,pygame,Python,Audio,Pygame,我想用pygame模块播放音频,但它不适合我。当我运行下面的代码时,它只会在不到一秒钟的时间内给出此消息,没有任何错误: pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html 代码: 我使用过其他著名的库playsound,但它对我的问题没有帮助。如果您知道其他用python播放歌曲的库,请告诉我。看起来您忘记了主事件循环: import pygame import sys p
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
代码:
我使用过其他著名的库playsound,但它对我的问题没有帮助。如果您知道其他用python播放歌曲的库,请告诉我。看起来您忘记了主事件循环:
import pygame
import sys
pygame.init() #<-- initializes video
pygame.mixer.init()
pygame.mixer.music.load("/home/hermes/Desktop/test/ring_tone.wav")
pygame.mixer.music.play()
SONG_END = pygame.USEREVENT + 1
pygame.mixer.music.set_endevent(SONG_END)
while True:
for event in pygame.event.get():
if event.type == SONG_END:
print("the song ended!")
pygame.quit()
sys.exit()
导入pygame
导入系统
pygame.init()#也许您可以使用pyaudio库。
我在github上用python播放音频文件
源代码:
和格式传输音频/视频文件可以使用ffmepg您是否尝试查看该卷是否正在生成?pygame.mixer.music.get_volume()pygame.mixer.music.set_volume()@Taku__它不做任何事情它引发了以下错误:pygame.error:视频系统未初始化
import pygame
import sys
pygame.init() #<-- initializes video
pygame.mixer.init()
pygame.mixer.music.load("/home/hermes/Desktop/test/ring_tone.wav")
pygame.mixer.music.play()
SONG_END = pygame.USEREVENT + 1
pygame.mixer.music.set_endevent(SONG_END)
while True:
for event in pygame.event.get():
if event.type == SONG_END:
print("the song ended!")
pygame.quit()
sys.exit()