2012-01-12 9 views
1

私はAVMutablecompositionを使用してAVplayerでオンラインビデオファイルを再生しようとしています。ビデオはブラウザで再生すると非常にうまく再生されますが、iPadでは再生できません。ここでAVFoundation - AVplayerでAVMutablecompositionでビデオが再生されなかった

はコードです:

self.composition = [AVMutableComposition composition]; 

NSURL *urlVideo = [NSURL URLWithString:@"{video location}"]; 
AVURLAsset *videoAsset = [[AVURLAsset alloc]initWithURL:urlVideo options:nil]; 

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

NSError *error = NULL; 

AVAssetTrack *videoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo]objectAtIndex:0]; 
CMTimeRange x = CMTimeRangeMake(kCMTimeZero, [videoAsset duration]); 
[compositionVideoTrack insertTimeRange:x ofTrack:videoTrack atTime:kCMTimeZero error:nil]; 

とAVPlayerを設定するコード:

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

self.player = [[AVPlayer alloc]initWithPlayerItem:playerItem]; 
AVPlayerLayer *layerVideo = [AVPlayerLayer playerLayerWithPlayer:self.player]; 
layerVideo.frame = self.view.layer.bounds; 
layerVideo.backgroundColor = [UIColor orangeColor].CGColor; 
layerVideo.position = CGPointMake(1024/2, 768/2-10); 

[self.view.layer addSublayer:layerVideo]; 
[self.player play]; 

私は "AVPlayerItem * playerItem = [AVPlayerItem playerItemWithAsset:videoAsset];" を使用している場合"AVPlayerItem * playerItem = [[AVPlayerItem alloc] initWithAsset:composition]の代わりに"私はビデオの再生を見ることができます。

誰でもAVMayerを使用してAVMayerを使ってビデオを再生する方法を知っていますか?

答えて

0

コードにはいくつかのエラーチェックがありませんが、そのまま動作します。

あなたがiPadの中でない限り、このラインは、オフスクリーンのプレーヤーが送信されます:

layerVideo.position = CGPointMake(1024/2, 768/2-10); 

その場合は、右の位置にしてみてください。

+0

実際に私の展開では、私はlayerVideoにbgの色を追加しました。ビデオが再生されずに画面にレイヤーが追加されているのがわかります – WilsonL

+0

背景色が見えますが、画面。オーディオ付きのビデオを使用するか、レイヤーにボーダーを追加してください(レイヤー全体が画面に表示されていることを確認する)。投稿したコードはiOS 5でもうまくいきます。 – djromero

関連する問題