python - 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()
这里有很多例子:Play MP3 in pygame
推荐阅读
- google-bigquery - Bigquery 可以扩展到 0 个工作人员吗?
- javascript - 如果所有数据库操作都是通过 Mongoose 完成的,注入仍然是一个问题吗?
- c++ - 为什么在调用函数时创建变量比创建变量并将其传递给函数要慢?
- android - 无法将 java.lang.String 类型的对象转换为 com.reazon.foodrunner.model.Favourite 类型
- javascript - 对象的问题 - 不会映射
- pytorch - 卷积 - 偶数和奇数大小的反卷积
- javascript - Object.fromEntries () 不尊重迭代器的顺序
- mongodb - MongoDB-Community 未在 Mac 上启动并出现错误
- r - 使用数据框中的不同值替换字符串的某些相等元素
- apache-kafka - Kafka Streams Processor API:直接写入kafka statestore,然后写入topic以避免延迟