我正在将一个音频mp3文件加载到python io.BytesIO缓冲区中。
然后我想用pygame.mixer多次播放这个音频文件。
它第一次运行得很好,但是看起来pygame.mixer.music.play删除了缓冲区。
源代码如下:
import io
import time
import pygame
with open(path_to_my_mp3_file, 'rb') as in_file:
buffer = io.BytesIO(in_file.read())
pygame.mixer.init()
pygame.mixer.music.load(buffer)
pygame.mixer.music.play() # works fine !
time.sleep(1)
pygame.mixer.music.load(buffer) # the buffer seems to be cleared
pygame.mixer.music.play() 我得到了这个错误:
File "test.py", line 17, in <module>
pygame.mixer.music.load(buffer)
pygame.error: Couldn't read from RWops有什么想法吗?
谢谢
PS:
我试过这个:
with open(path_to_my_mp3_file, 'rb') as in_file:
buffer = in_file.read()
pygame.mixer.init()
pygame.mixer.music.load(io.BytesIO(buffer))
pygame.mixer.music.play()
time.sleep(1)
pygame.mixer.music.load(io.BytesIO(buffer))
pygame.mixer.music.play()它可以工作,但我认为这段代码的性能较差
https://stackoverflow.com/questions/44482149
复制相似问题