0

I'm generating an .m4a from a video recorded during a AVCaptureVideoPreviewLayer session (using the wonderful PBJVision). I then generate an m4a file from the video captured:

AVAssetExportSession *exportSession=[AVAssetExportSession exportSessionWithAsset:myasset presetName:AVAssetExportPresetAppleM4A];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *audioPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.m4a",audioFileName]];
exportSession.outputURL=[NSURL fileURLWithPath:audioPath];
exportSession.outputFileType=AVFileTypeAppleM4A;

[exportSession exportAsynchronouslyWithCompletionHandler:^{
    if (exportSession.status==AVAssetExportSessionStatusFailed) {
        NSLog(@"failed");
        }
else {
    [_audioFilePaths setObject:audioPath forKey:audioFileName]
    }

and then i try to play

AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[_audioFilePaths objectForKey:square]] error:&error];

NSError *error;
player.numberOfLoops =0;
if (player == nil){
    NSLog(@"%@", [error description]);
    }
 else {
    [player play];
    }

but nothing plays. I am not ending the video capture session but i've verified the m4a is processed and recorded on the device. i've tried loaded mp3s in the project but they also dont work.

thought this was relevant but didn't help (though i just put it in the didViewLoad call.) AVAudioPlayer turns off iPod - how to work around?

lastly, this is a class within a spritekit project.

Community
  • 1
  • 1
kidnim
  • 1,477
  • 2
  • 10
  • 13
  • i can't find that line of code where we save data in filemanager... then how you fetch that data in your AVAudioPlayer – Divyanshu Sharma Jan 06 '16 at 04:43
  • Are you sure `[_audioFilePaths objectForKey:square]` references the correct file url? – Lyndsey Scott Jan 06 '16 at 04:50
  • @DivyanshuSharma The export session stores the data at its outputURL. – Lyndsey Scott Jan 06 '16 at 04:51
  • @DivyanshuSharma indeed, i pass the outputURL to the dictionary called from later. edited to add. – kidnim Jan 06 '16 at 12:49
  • @LyndseyScott i'm certain yes. just to be sure, i actually tried to just initiate the audioplayer and play the sound in the exportsession completionhandler and still no play – kidnim Jan 06 '16 at 12:49
  • @kidnim I don't know what the issue is, but it is in fact 100% necessary for you to either initiate the audio player in the export session competition handler or have some other way of knowing the export is complete before setting the AVAudioPlayer's URL. – Lyndsey Scott Jan 06 '16 at 15:44

0 Answers0