English 中文(简体)
AVFoundation - 录像带在ARVutablecomposition with AVplayer
原标题:AVFoundation - Video didn t play in AVMutablecomposition with AVplayer

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的录像?

问题回答

你的法典缺乏对两条错误的核对,但它也发挥了作用。

除非你重新插入一篮子,否则会把参与者送走:

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

如果是这样的话,就以正确的立场进行审判。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签