[英]Pyinstaller pygame.mixer don't play mp3 files?
error:错误:
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 command: pyinstaller 命令:
python -m eel main.py web --console --onefile --icon=ico.ico
mp3 files don't play but wav files works... mp3 文件不播放,但 wav 文件有效...
Try the following snippet:尝试以下代码段:
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)
This should play the music and run the rest of the game.这应该播放音乐并运行游戏的其余部分。
You are able to do the following as well:您还可以执行以下操作:
import pygame
mp3_file = 'song.mp3'
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(mp3_file)
pygame.mixer.music.play()
pygame.event.wait()
But the game will stop executing and wait for the mp3 to finish.但游戏将停止执行并等待 mp3 完成。 This is because of pygame.event.wait()
这是因为pygame.event.wait()
There are many examples here: Play MP3 in pygame这里有很多例子: 在pygame中播放MP3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.