2

私は現在、.mp4 のオーディオ トラックのみを再生する iPhone アプリに取り組んでいます。Player は再生を開始しますが、音が聞こえません。

コードは次のとおりです。

    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];
4

1 に答える 1