问题
UPDATE 10/9/2016: I had opened up Radar #28425770 with Apple on 9/22/2016 for the following defect and they have just marked is as a duplicate (of Radar #28327056), so this appears to be a known bug within iOS10.
I've encountered an error invoking the AudioToolbox / MusicPlayer API method "MusicSequenceFileLoad()" to load the contents of a MIDI file (from the given URL) into a music sequence on an iOS10 iPad Pro (wifi model) and would greatly appreciate some assistance from the community in debugging this.
Research / observations I've been able to make thus far:
This code has been working without issue in production on iOS7, 8, and 9 for 2+ years and also runs without issue on the iOS 10 Simulator but returns an error only on a iOS 10.0.1 iPad Pro Wifi Model.
I was not able to recreate on other devices and also asked some friends to try as well. Devices tested without issue: iPhone 6+, iPad Mini 4th Gen, iPad Pro Cellular.
The first time the VC is displayed which uses this MIDI file all processing runs without any issues. It's only the second time (or sometimes third) that the VC is loaded where the app crashes. The issue can be recreated consistently 100% of the time.
Checking the OSStatus result code from calling this function simply returns a value of -1 and does not indicate the reason for the failure.
No crash report, exception information or call stack is available when debugging within Xcode.
Profiling for memory management issues (allocations, leaks, zombies), has not shown any information related to the crash; turning on the Zombie Objects option did not reveal any Zombie Objects.
Analyzing the application did not reveal any areas where memory was not being released.
Changing the objects to be static did not have any impact so this seems that it would not be memory related.
If anyone has any suggestions on other ways in which I could debug this issue it would be greatly appreciated. I originally thought it could be related to memory management however from what I can see I am handling memory appropriately (using ARC for the application and releasing C-API objects as needed) and profiling has not revealed any issues that I can see.
Code sample:
@property (readwrite, nonatomic) MusicPlayer midiMusicPlayer;
@property (readwrite, atomic) MusicSequence masterMidiMusicSequence;
- (void)initializeMusicPlayerAndMasterSequenceWithFile:(NSString *)midiFilename
{
CheckError(NewMusicPlayer(&_midiMusicPlayer), "NewMusicPlayer: _midiMusicPlayer");
CheckError(NewMusicSequence(&_masterMidiMusicSequence), "NewMusicSequence: _masterMidiMusicSequence");
NSString *midiFilePath = [NSBundle pathForResource:midiFilename
ofType:@"mid"
checkDocumentsDirectory:YES];
NSURL *midiFileURL = [NSURL fileURLWithPath:midiFilePath];
// Crash is encountered on the following line:
CheckError(MusicSequenceFileLoad(self.masterMidiMusicSequence, (__bridge CFURLRef)midiFileURL, 0, 0), "MusicSequenceFileLoad");
}
回答1:
I received some guidance from an Apple engineer via the Core Audio Mailing List and have successfully implemented the proposed work-around for this issue in iOS10.
By updating the "errno" value to 0 after a failed call, subsequent calls to 'MusicSequenceFileLoad' generate a successful response. Therefore, I've amended my code as follows:
OSStatus statusOfInitialAttempt = CheckError(MusicSequenceFileLoad(self.masterMidiMusicSequence, (__bridge CFURLRef)midiFileURL, 0, 0), "MusicSequenceFileLoad");
if (statusOfInitialAttempt == -1) {
errno = 0;
OSStatus statusOfSecondAttempt = CheckErrorAndReturnOnFailure(MusicSequenceFileLoad(self.masterMidiMusicSequence, (__bridge CFURLRef)midiFileURL, 0, 0), "MusicSequenceFileLoad");
if (statusOfSecondAttempt == -1) {
// Handle error case
}
}
... where the CheckError() function simply checks the OSStatus return value against known OSStatus codes and is similar to this one on GitHub (originally created by Chris Adamson from his blog post / presentation "Core Audio Cranks It Up").
I understand that this issue is expected to be resolved in a future iOS update according to what was posted on the Core Audio Mailing List.
回答2:
Did you try to add NSAppleMusicUsageDescription
to your Info.plist
?
Starting in iOS 10, your Info.plist file must include a purpose string, for display in the permission alert, for each such item. If your app attempts to access a protected item without you having provided a corresponding purpose string, your app exits.
See App Programming Guide for iOS for more detailed info.
来源:https://stackoverflow.com/questions/39437155/musicsequencefileload-returns-1-on-ios10-audiotoolbox-musicplayer