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

Set playback position of MIDI file in pygame

我非常希望能够使用 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

Copy/Paste 来自官方 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

midi 文件不支持此功能,文档中写道:“不支持其他文件格式(OGG、MP3 和 MOD 除外)。较新版本的 SDL_mixer 有更好的定位支持比早期的支持。如果特定格式不支持定位,则会引发 SDLError。“