I am working on playing a online video file with AVplayer using AVMutablecomposition. The Video plays very fine when I play it on browser but I just cant get it play on my 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];
If I use "AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:videoAsset];" instead of "AVPlayerItem *playerItem = [[AVPlayerItem alloc]initWithAsset:composition];" then I can see the video playing.
任何人都知道如何使用AVplayer与ARVutablecomposition的录像?