python - 在pygame中设置MIDI文件的播放位置

标签 python audio pygame midi

我真的希望能够使用 pygame.mixer.music 模块从 MIDI 文件中的某个位置开始播放,但我收到以下错误:

error: Position not implemented for music type

(这是 pygame 1.9.1 的版本。)

我看不到任何其他可以使用这种 MIDI 到音频合成的库。有什么建议么?

最佳答案

我在 python 2.7.x 上有 pygame 1.9.1。我能够模拟AttributeError: 'module' object has no attribute 'set_pos'错误。
根据安装版本随附的文档,位于 C:\Python27\Lib\site-packages\pygame\docs
1) 首选:
pygame 1.9.2 及以上版本有 pygame.mixer.music.set_pos功能。因此,您可能想尝试将 pygame 升级到 1.9.2
pygame 网站上的官方文档是针对我们所指的 1.9.2 的。
Here is a link到官方 1.9.2 pygame 文档

2) 第二选择:
接下来,使用当前版本,您可以尝试使用pygame.mixer.music.play(loop= ?, start=? )参数,但这仅适用于 MP3 和 OGG。
因此,您需要将现有的 MIDI 文件转换为 MP3/OGG 才能使此选项起作用。

最好和更简单的选择是将 pygame 升级到 1.9.2

从官方 1.9.1 文档中复制/粘贴

pygame.mixer.music.play Start the playback of the music stream

pygame.mixer.music.play(loops=0, start=0.0): return None
This will play the loaded music stream. If the music is already playing it will be restarted.

The loops argument controls the number of repeats a music will play. play(5) will cause the music to played once, then repeated five times, for a total of six. If the loops is -1 then the music will repeat indefinitely.

The starting position argument controls where in the music the song starts playing. The starting position is dependent on the format of music playing. MP3 and OGG use the position as time (in seconds). MOD music it is the pattern order number. Passing a startpos will raise a NotImplementedError if it cannot set the start position

关于python - 在pygame中设置MIDI文件的播放位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35530050/

相关文章:

python - 如何使用 Matplotlib 在 Python 中计算轮廓内的面积?

python - 如何解决pygame中这些圆圈的碰撞?

pygame - 带 Pillow 的 Python 3.3 - 导入错误 : No module named 'Image'

python - 如何实现黑屏和网格绘制?

python - 在基于 sqlalchemy 的 Web 应用程序中,将 db_session 相关语句放在哪里?

Python:检查给定目录中是否存在任何文件

ios - 获取系统音量 iOS

windows - ffmpeg 标准化视频的响度

javascript - HTML5 音频随机播放

python - 空集文字?