AVMutablecomposition を使用して、AVplayer でオンライン ビデオ ファイルを再生する作業を行っています。ビデオをブラウザで再生すると問題なく再生されますが、iPad では再生できません。
コードは次のとおりです。
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];」の代わりに その後、ビデオの再生を見ることができます。
AVplayer と AVMutablecomposition を使用してビデオを再生する方法を知っている人はいますか?