此代码适用于在iOS 8.4中循环播放MusicTrack,但在使用MusicPlayerSetSequence
设置序列时将停止iOS 9.0下的应用程序var loopInfo = MusicTrackLoopInfo(loopDuration: 1.0,numberOfLoops: 0)
MusicTrackSetProperty(track, UInt32(kSequenceTrackProperty_LoopInfo), &loopInfo, UInt32(sizeofValue(loopInfo)))
还有另一种方法让音轨在iOS 9中循环播放吗?
答案 0 :(得分:0)
其他人遇到了类似的问题:https://forums.developer.apple.com/thread/9940当前解决方法的一般想法是,一旦到达音轨的末尾,将播放标记设置回0。
例如,在您用于启动音乐播放器的方法中使用此功能:
MusicTrack track = NULL;
MusicTimeStamp trackLen = 0;
UInt32 trackLenLen = sizeof(trackLen);
//Get main track
MusicSequenceGetIndTrack(musicSequence, 0, &track);
//Get length of track
MusicTrackGetProperty(track, kSequenceTrackProperty_TrackLength, &trackLen, &trackLenLen);
//Create UserData for User Event with any data
static MusicEventUserData userData = {1, 0x09};
//Put new user event at the end of the track
MusicTrackNewUserEvent(track, trackLen, &userData);
//Set a callback for when User Events occur
MusicSequenceSetUserCallback(musicSequence, sequenceUserCallback, musicPlayer);
然后你可以有一个回调函数:
static void sequenceUserCallback(void *inClientData,
MusicSequence inSequence,
MusicTrack inTrack,
MusicTimeStamp inEventTime,
const MusicEventUserData *inEventData,
MusicTimeStamp inStartSliceBeat,
MusicTimeStamp inEndSliceBeat)
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
MusicPlayerSetTime((MusicPlayer) inClientData, 0.0);
}];
}
将播放器设置为零。