I am able to successfully create a simple app that plays sound using the code below. The problem however is if I change the asset from being an mp3 to an m4a (with aac encoding). No sound is produced, yet the duration of the composition matches the length of the added sample.
NSError *error;
AVMutableComposition* composition = [AVMutableComposition composition];
AVURLAsset* audioAsset1 = [[AVURLAsset alloc]initWithURL:[NSURL URLWithString:@"http://www.myserver.com/sample.mp3"] options:nil];
AVMutableCompositionTrack *audioTrack1 = [composition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
[audioTrack1 insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset1.duration)
ofTrack:[[audioAsset1 tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
atTime:kCMTimeZero
error:&error];
NSLog(@"%@", error);
playerItem = [AVPlayerItem playerItemWithAsset:composition];
player = [AVPlayer playerWithPlayerItem:playerItem];
[player play];
Can anyone help?