1
我正在使用AVMutablecomposition與AVplayer一起播放在線視頻文件。當我在瀏覽器上播放視頻時,視頻播放效果非常好,但我無法在iPad上播放。AVFoundation - 視頻沒有在AVMutablecomposition中與AVplayer一起玩
下面的代碼:
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];」然後我可以看到播放的視頻。
任何人都知道如何使用具有AVMutablecomposition的AVplayer播放視頻?
謝謝,但事實上,在我的部署中,我在layerVideo中添加了一個bg顏色,並且我可以看到該圖層已添加到屏幕上(沒有視頻播放) – WilsonL 2012-01-16 03:29:25
您可以看到背景顏色,並且仍然可以關閉視頻屏幕。嘗試使用帶音頻的視頻或爲圖層添加邊框(以檢查整個圖層是否在屏幕上)。你發佈的代碼在iOS 5中工作正常。 – djromero 2012-01-16 10:06:52