MIDI player looping problems (21825100)

Running under beta 3.

Looping a simple MIDI file with MusicPlayer causes lockup.

If I set numberOfLoops to 0 in MusicTrackLoopInfo and playback the MIDI file, it will play once and then start locking up. It seems like it starts sending to itself and feeding back upon itself.


Bug Report: 21825100

Replies

Having this same issue

The problem is still there in beta 5. Wow, if it ships like this, it will be terrible. No fix for this.

Reported and sent sample project with problem. Long ago.

21825100

From the Core Audio mailing list:

> This is a known issue that will be fixed in an upcoming release. It was not reported in time to be fixed in 9.0.

> -DS

Thanks for taking the time to submit a bug report.

YES IT WAS REPORTED IN TIME! Beta 3 <-- with full sample code.

How much time do they need to fix this problem? I guess it's not an easy fix.

OK this got me so irritated that I found a work-around. It took me since beta 3, but it works.

I tried all sorts of things but this will work.

Don't set numberOfLoops at all, OR set numberOfLoops = 1; // means loop once

Now make a variable (i.e. myVariableToKeepTrackOfAddedCopies) that keeps track of the number of times you will actually perform the following:


In your MIDIReadProc at some point BEFORE the track has finished playing, do the following:


// Copy the track to itself - effectively doubling the length

MusicTrack theTrack=nil;

MusicTrackGetProperty(theTrack, kSequenceTrackProperty_TrackLength, &trackLen, &trackLenLen);

trackLen = 4.0; //<-- this is your real track length

MusicTrackCopyInsert(theTrack, 0, trackLen, theTrack, 0);

myVariableToKeepTrackOfAddedCopies++;

So now your track is twice as long before it ends and the track will continue. This will work the same as looping except you are taking up more memory since you are making the track length longer after each iteration.


When you stop the sequence/track, cut the track back to the original size.


MusicTrackCut(theTrack, 4.0, 4.0 + (4.0*myVariableToKeepTrackOfAddedCopies));

MusicTrackGetProperty(theTrack, kSequenceTrackProperty_TrackLength, &trackLen, &trackLenLen);

Irritating, but it works. I just verified on iOS9 beta 5. Hope it helps.

I went with a different workaround that removed all usage of the MusicPlayer, MusicTrack, and MusicSequence APIs. I added a render notification callback (AudioUnitAddRenderNotify) to the AUSampler that is responsible for managing time (beats) and firing off appropriate MusicDeviceMIDIEvent calls to play specified samples at the appropriate beats. Looping is handled within this callback.

WOW, so you are parsing the MIDI File yourself and handling the timing etc...?

That is a lot of work. Congratulations!

Great, It would be nice to see some code

is a very interesting solution

Awesome, before the bug fixed, this is the best solution. Thanks.

Randomizer - Thanks for this post and the bug report. I've run into the same issue, and appreciate the technical solution you've proposed but unfortunately it doesn't fit my functional requirements. Quite the tough spot to be in - my app is live in the store and impacted by this issue.


I would love to remove my dependency on these APIs as per mstultz's suggestion, but as you mentioned the amount of work is a bit overwhelming and I'm not sure I could accomplish this in a reasonable amount of time.


I've also created a bug report in case it helps to speed things along: 22672764


Out of curiosity, have you received any updates from Apple as to when this might be resolved? Does not seem to be corrected yet in the latest 9.1 beta.

I am in the same boat with my app Gumdrops. I pray Apple will fix this in the next point release to ios9.

hello


This bug is also causing problems with the Groove Freedom application, but there is no solution. People who have paid the application and now can not use it, what we do?


thanks

Oct 3. The problem still exists.