New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opening a file from the iPod library makes EZAudioFile crash #12
Comments
Interesting, I think URLs referenced by the MPMediaItem can only be opened using the AVFoundation. I'll take a look and see if I can find a way around. |
Are you planning on integrating it in EZAudio 1.0? |
Hi SyedhAli, Also, frequent change to seek position (scrubbing the slider) crashes the application with EXC_BAD_ACCESS. |
@raghunathkavuri how did you get this working? Any advice would be appreciated! @syedhali was a solution to this ever figured out? When creating a new
|
Having the same issue get EXC_BAD_ACCESS at [EZAudio checkResult:ExtAudioFileSetProperty(_audioFile, With AssetURL |
Guys did you found any solution? |
So any file coming from the iPod library as an MPMediaItem will have a path prefix, ipod://, which doesn't agree with the EZAudioFile. Here's an approach to create an EZAudioFile using the AVAssetExportSession to export the audio data from the MPMediaItem to the app's bundle. //
// Creates an EZAudioFile from an MPMediaItem representing a song coming from
// an iOS device's iPod library. Since an MPMediaItem's URL is always prefixed
// with an ipod:// path we must use the AVAssetExportSession to first export
// the song to a file path that the EZAudioFile can actually find in the app's bundle.
//
- (void)openMediaItem:(MPMediaItem *)item
completion:(void(^)(EZAudioFile *audioFile, NSError *error))completion
{
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
NSString *title = [item valueForProperty:MPMediaItemPropertyTitle];
if (url)
{
//
// Create an AVAudioExportSession to export the MPMediaItem to a non-iPod
// file path url we can actually use for an EZAudioFile
//
AVURLAsset *asset = [AVURLAsset assetWithURL:url];
AVAssetExportSession *exporter = [AVAssetExportSession exportSessionWithAsset:asset
presetName:AVAssetExportPresetAppleM4A];
exporter.outputFileType = @"com.apple.m4a-audio";
NSString *exportURLPath = [[self applicationDocumentsDirectory] stringByAppendingFormat:@"/%@.m4a", title];
NSURL *exportURL = [NSURL fileURLWithPath:exportURLPath];
exporter.outputURL = exportURL;
//
// Delete any existing path in the bundle if one already exists
//
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:exportURLPath])
{
NSError *error;
[fileManager removeItemAtPath:exportURLPath error:&error];
if (error)
{
NSLog(@"error deleting file: %@", error.localizedDescription);
}
}
//
// Export the audio data using the AVAudioExportSession to the
// exportURL in the application bundle
//
[exporter exportAsynchronouslyWithCompletionHandler:^{
AVAssetExportSessionStatus status = [exporter status];
switch (status)
{
case AVAssetExportSessionStatusCompleted:
{
EZAudioFile *file = [EZAudioFile audioFileWithURL:exportURL];
completion(file ,nil);
break;
}
case AVAssetExportSessionStatusFailed:
{
completion(nil, exporter.error);
break;
}
default:
{
NSLog(@"Exporter status not fialed or complete: %ld", status);
break;
}
}
}];
}
else
{
NSError *error = [NSError errorWithDomain:@"com.myapp.sha"
code:404
userInfo:@{ NSLocalizedDescriptionKey : @"Media item's URL not found" }];
completion(nil, error);
}
} Usage: //
// Get an EZAudioFile from the first valid MPMediaItem (meaning it has a URL)
// from the user's iPod library
//
MPMediaQuery *everything = [[MPMediaQuery alloc] init];
MPMediaItem *song = [[everything items] firstObject];
[self openMediaItem:song
completion:^(EZAudioFile *audioFile,
NSError *error)
{
NSLog(@"audio file: %@, error: %@", audioFile, error);
}]; I could build this into the EZAudioFile, but it would require including the MediaPlayer API as a dependency for EZAudio on iOS devices. Anyone feel strongly that this should be integrated directly into EZAudio? |
Going to close this ticket for now |
ipod-library urls were working in 0.0.6 but I just upgraded to 1.1.1 and it stopped working. I am now required to do the above ? What I'm seeing is the EZAudioFile dealloc as soon as i create it and crash on dealloc with: "Error: Failed to dispose of ext audio file (-50)" |
@solomon23 Were you able to find a solution to this? |
Yea: master...solomon23:remove-file-check On Wed, Dec 9, 2015 at 6:13 PM, Uzoma Orji notifications@github.com wrote:
|
2016-07-14 16:21:55.911 AppEditMusic[2922:914540] outputs: ( |
You have to copy item from iPod library to sandbox. |
Thank you very much ! :) 2016-07-14 16:43 GMT+07:00 saitjr notifications@github.com:
|
Syed, I'm just starting with EZAudioPlayer. Is it still the case that one must copy an iPod Library song into the Documents folder before playing it with this class? If so, how are you and other users handling the case where two songs have the same title? (I suppose one could use the songs' IDs but wondering if you have something better.) How long does it take, in your experience, for an iPhone 5s to copy a 5min song? Is it as quick as a raw file duplication? A couple of people in this thread have noted that EZAudio DID play iPod URLs in an early version. Did you ever check out whether this is true and perhaps how you can get this functionality back? Also, someone noted that playing iPod URLs works in iOS 7+ but not in 6. It seems that can't be true, but just wondering. Basically, I'm trying to avoid copying files like this. It's a fuss to either keep track of which files have been copied and/or when to delete them. Thanks so much for making this library! I've been using EZMicrophone for years now in an LED display client app called LED Lab. I'm looking forward to using more of the library soon! |
No, it is not necessary to copy the files, you should be able to play them directly, but you need to make a small few changes to some of the error handling in the library. There is an issue in the library when validating the url. You should be able to search other issues for the things that need to be changed. I believe this is the issue in EZAudioFile:
|
Thanks dxclancy! Yes, MPMediaItem's URLs are useable by EZAudioFile, once you take out the "fileExistsAtPath" call. I ended up tweaking a LOT of code in EZAudio. There were a number of loose ends and things that imagine would sometimes crash. (eg: Changing the length of buffers in an AudioBufferList.) Things are working REALLY well in LED Lab now! |
@dxclancy thankyou , use your code, has solved my problem! |
Hey!
I tried to open an MPMediaItem file using this code:
I also tried using to copy the song in a temporary folder using AVAssetExportSession but it didn't work.
The text was updated successfully, but these errors were encountered: