我正在使用下面的代码在ios中播放midi文件,但我该如何循环播放歌曲? 有没有像player.loop = true?
NewMusicSequence(&mySequence);
NSURL * midiFileURL = [NSURL fileURLWithPath:midPath];
MusicSequenceFileLoad(mySequence, (__bridge CFURLRef)midiFileURL, 0, kMusicSequenceLoadSMF_ChannelsToTracks);`
NewMusicPlayer(&player);
MusicPlayerSetSequence(player, mySequence);
MusicPlayerPreroll(player);
MusicPlayerStart(player);
提前致谢。
答案 0 :(得分:1)
我通过为每个曲目设置循环信息来解决它。
UInt32 tracks;
if (MusicSequenceGetTrackCount(sequence, &tracks) != noErr)
for (UInt32 i = 0; i < tracks; i++) {
MusicTrack track = NULL;
MusicTimeStamp trackLen = 0;
UInt32 trackLenLen = sizeof(trackLen);
MusicSequenceGetIndTrack(sequence, i, &track);
MusicTrackGetProperty(track, kSequenceTrackProperty_TrackLength, &trackLen, &trackLenLen);
MusicTrackLoopInfo loopInfo = { trackLen, 0 };
MusicTrackSetProperty(track, kSequenceTrackProperty_LoopInfo, &loopInfo, sizeof(loopInfo));
NSLog(@"track length is %f", trackLen);
}
答案 1 :(得分:0)
如果有人在循环播放音乐序列并遵循Rick Li的指令或此处的指令https://gist.github.com/genedelisa/7b440f128db96c3ba66f时遇到问题,我发现MusicTrackLoopInfo代码仅在曲目的持续时间实际上为 < / em>足够短,以至于我有耐心地坐着听它循环播放。例如,我尝试在开始时单击一下以使轨道循环播放,以使其每秒重复一次。但是单个音符的持续时间实际上是100秒,因此,即使我按照里克·李(Rick Li)的说明设置了循环,我也必须等待近两分钟才能听到循环。我希望这可以帮助那些困惑或沮丧的人无法在iOS / AudioToolbox中循环播放音乐序列/ MIDI轨道。确保调用GetProperty kSequenceTrackProperty_TrackLength并检查您的trackLen值不是很大,即使您确信它的值很小!