Pyinstaller pygame.mixer 不播放 mp3 文件?



错误:

Traceback (most recent call last):
File "src\gevent\greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
File "eel__init__.py", line 259, in _process_message
File "main.py", line 40, in play_music
pygame.error: Failed loading libmpg123-0.dll: The specified module could not be found.
2020-08-28T18:46:27Z <Greenlet at 0x4b29138: _process_message({'call': 1.305899873486772, 'name': 'play_music', , <geventwebsocket.websocket.WebSocket object at 0x0)> failed with error

pyinstaller命令:

python -m eel main.py web --console --onefile --icon=ico.ico

mp3文件无法播放,但wav文件可以工作

尝试以下片段:

import pygame
mp3_file = 'song.mp3'
pygame.init()
pygame.mixer.init()
clock = pygame.time.Clock()
pygame.mixer.music.load(mp3_file)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
clock.tick(10)

这应该播放音乐并运行游戏的其余部分。

您还可以执行以下操作:

import pygame
mp3_file = 'song.mp3'
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(mp3_file)
pygame.mixer.music.play()
pygame.event.wait()

但游戏将停止执行,等待mp3结束。这是因为pygame.event.wait()

这里有很多例子:在pygame 中播放MP3

最新更新