AVFoundation - Видео не воспроизводилось в AVMutablecomposition с AVplayer - PullRequest
1 голос
/ 12 января 2012

Я работаю над воспроизведением онлайн-видеофайла с AVplayer с помощью AVMutablecomposition.Видео воспроизводится очень хорошо, когда я играю в браузере, но я не могу воспроизвести его на своем 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: состав];"тогда я вижу, как воспроизводится видео.

Кто-нибудь знает, как воспроизводить видео, используя AVplayer с AVMutablecomposition?

1 Ответ

0 голосов
/ 13 января 2012

В вашем коде отсутствует пара проверок ошибок, но он работает как есть.

Если вы не находитесь на iPad, эта строка будет выводить плеер за пределы экрана:

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

Если этослучай, попробуйте с правильной позиции.

...