3
我想从我的应用程序使用AVPlayer播放本地视频。我已到处寻找,但找不到任何有用的教程/演示/文档。这是我正在尝试的,但它不是在玩。任何想法为什么?该URL是有效的,因为我使用同一个成功地使用MPMoviePlayer播放视频。从应用内播放视频?
Video *currentVideo = [videoArray objectAtIndex:0];
NSString *filepath = currentVideo.videoURL;
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
AVURLAsset *asset = [AVURLAsset assetWithURL: fileURL];
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset: asset];
self.player = [[AVPlayer alloc] initWithPlayerItem: item];
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.player];
self.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
layer.frame = CGRectMake(0, 0, 1024, 768);
[self.view.layer addSublayer: layer];
[self.player play];
非常感谢!对不起,延迟接受! –
@LuisCien我现在面临同样的问题,我已经使用你的代码。但它返回了我'AVKeyValueStatusFailed',请看我的问题,并建议我一些,如果你明白。 http://stackoverflow.com/questions/29255776/cannot-get-the-duration-of-mp4-file-by-using-avasset-or-avurlasset –