2011-07-18 11 views
3

私は、1つのビデオトラックと複数のオーディオトラック(異なる言語用)を持つことができるアプリケーションでプレーヤーを作ろうとしています。1つのビデオトラックと複数のオーディオトラックを持つAVPlayer

は、私はこれをやったが、プレーヤーが起動しません。

AVMutableComposition *composition = [AVMutableComposition composition]; 
AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:urlVideo options:nil]; 

AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; 
NSError* error = NULL; 

[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,videoAsset.duration) 
           ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo]objectAtIndex:0] 
           atTime:kCMTimeZero 
           error:&error]; 

NSMutableArray *allAudio = [[NSMutableArray alloc]init]; 
for (int i=1; i < [allAudioTracks count]; i++) { 
    NSURL *audioURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",URL_MEDIA,[[allAudioTracks objectAtIndex:i]audio]]]; 
    AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audioURL options:nil]; 
    [allAudio addObject:audioAsset]; 
    [audioAsset release]; 
    [audioURL release]; 
} 

for (int i=0; i < [allAudio count]; i++) { 
    NSError* error = NULL; 
    AVURLAsset *audioAsset = (AVURLAsset*)[allAudio objectAtIndex:i]; 
    //audioAsset = [allAudio objectAtIndex:i]; 

    AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; 
    [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,audioAsset.duration) 
            ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio]objectAtIndex:0] 
            atTime:kCMTimeZero 
             error:&error]; 

    NSLog(@"Error : %@", error); 
    //[allCompositionTrack addObject:compositionAudioTrack]; 
    [audioAsset release]; 
} 

と私はこのように私のプレーヤーを起動しよう:

AVPlayerItem *playerItem = [[AVPlayerItem alloc]initWithAsset:composition]; 

player = [[AVPlayer alloc]initWithPlayerItem:playerItem]; 

layerVideo = [AVPlayerLayer playerLayerWithPlayer:player]; 
layerVideo.frame = CGRectMake(0, 0, 480, 320); 
[self.view.layer addSublayer:layerVideo]; 

[player play]; 

しかし、何もAPPENDを。

NSURL * audioURL = [NSURL URLWithString:[NSStringのstringWithFormat:@ "%@%@"、URL_MEDIA、[ おかげで(私の英語:)のためと申し訳ありません)あなたの助け

答えて

2

私はこのラインを考えます[allAudioTracks objectAtIndex:i] audio]]];

は、ファイルを使用している場合は、URLWithStringの代わりにfileURLWithStringである必要があります。よくある間違い。お知らせ下さい。

関連する問題