首页 文章

无法用声音播放AVMutableComposition

提问于
浏览
2

我目前正在开发一款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];

1 回答

  • 2

    我遇到了类似的问题,发现AVFoundation对你的作文格式非常无情 . 我最终回答了我自己的问题 - 这与你的问题相同 .

    看看我的帖子:iOS AVFoundation Export Session is missing audio

相关问题