我能够使用下面的代码成功创建一个播放声音的简单应用程序。然而问题是,如果我将资产从 mp3 更改为 m4a(使用 aac 编码)。不会产生声音,但乐曲的持续时间与添加样本的长度相匹配。
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];
任何人都可以帮忙吗?