我目前正在开发一款iPhone应用程序,只能播放.mp4的音轨。播放器开始播放,但我听不到任何声音。
以下是代码:
NSURL *videoUrl = [NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
AVMutableComposition* composition = [AVMutableComposition composition];
AVMutableCompositionTrack *track = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
AVURLAsset* videoAsset = [AVURLAsset URLAssetWithURL:videoUrl options:nil];
AVAssetTrack *audioTrack = [[videoAsset tracksWithMediaType:AVMediaTypeAudio]objectAtIndex:0];
NSError *error = nil;
BOOL success = [track insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:audioTrack atTime:kCMTimeZero error:&error];
if (!success)
{
NSLog(@"error: %@", error);
}
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:composition];
self.player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[self.player play];
答案 0 :(得分:2)
我遇到了类似的问题,发现AVFoundation对你的作文格式非常不宽容。我最终回答了我自己的问题 - 这与你的问题相同。