我在 iOS 5 上使用 CoreAudio 来播放 MIDI 文件。我已经完成了所有设置,一切正常,一切都很好,除非我想在播放过程中从头开始重新开始序列。为此,我自然会调用:
if (MusicPlayerSetTime(musicPlayer, (MusicTimeStamp)0.0) != noErr)
[NSException raise:@"playMIDI" format:@"Can't reset the player"];
我没有收到任何错误,但是进行此调用会完全停止播放,而不是(如文档中所述)继续从新位置播放。我也试过这个(以及许多其他相同类型的组合):
Boolean isPlaying = NO;
if (MusicPlayerIsPlaying(musicPlayer, &isPlaying) != noErr)
[NSException raise:@"playMIDI:" format:@"Can't get MusicPlayer play state"];
if (isPlaying) {
if (MusicPlayerStop(musicPlayer) != noErr)
[NSException raise:@"playMIDI:" format:@"Can't stop MusicPlayer"];
}
if (MusicPlayerSetSequence(musicPlayer, musicSequence) != noErr)
[NSException raise:@"playMIDI:" format:@"Can't set sequence for MusicPlayer"];
if (MusicPlayerSetTime(musicPlayer, (MusicTimeStamp)0.0) != noErr)
[NSException raise:@"playMIDI" format:@"Can't reset the player"];
if (MusicPlayerSetPlayRateScalar(musicPlayer, 1.0) != noErr)
[NSException raise:@"playMIDI" format:@"Can't set speed"];
if (MusicPlayerStart(musicPlayer) != noErr)
[NSException raise:@"playMIDI" format:@"Can't start MusicPlayer"];
没有喜悦,同样的效果。
但是,如果我更改 MusicSequence,则新的 MusicSequence 可以正常播放。所以我走到了极端,从同一个 MIDI 文件创建两个 MusicSequence 并从一个切换到另一个。不高兴,iOS 知道我想播放同一个文件两次并禁止它。我必须等到序列完全播放完才能再次播放。扑朔迷离。
任何的想法?
谢谢