FWIW, if you want the whole sequence to loop, you can set a user event at the end of the sequence and use the callback to trigger a reset of the time to the start of the sequence.
-(void)handleUserEvent:(NSValue *)theEventValue{
UserEvent theEvent;
[theEventValue getValue:&theEvent];
switch(theEvent.type){
case UserExitEvent:
if (self.looping){
[self skipToTime:0];
} else {
[self stop];
}
break;
default:
break;
}
if (self.userEventBlock != nil){
self.userEventBlock(theEvent);
}
}
-(void)skipToTime:(NSTimeInterval)time{
MusicPlayerStop(self.player);
MusicPlayerSetTime(self.player, time);
MusicPlayerStart(self.player);
}
void MidiUserCallback (
void *inClientData,
MusicSequence inSequence,
MusicTrack inTrack,
MusicTimeStamp inEventTime,
const MusicEventUserData *inEventData,
MusicTimeStamp inStartSliceBeat,
MusicTimeStamp inEndSliceBeat
){
UserEvent *theEvent = (UserEvent *)inEventData;
MidiFilePlayer *player = (__bridge MidiFilePlayer *)inClientData;
NSValue *eventValue = [NSValue valueWithBytes:theEvent objCType:@encode(UserEvent )];
dispatch_async(dispatch_get_main_queue(), ^(){
[player handleUserEvent:eventValue ];
});
}