赞
踩
NSURL *sourceMovieURL = [NSURLURLWithString:@"http://v.jxvdy.com/sendfile/V7bzjsH5sIZlBzVG7t7qbL1u-y1_k6E0DCtzyZ8iv-pRF3GmewWOj-HQ_grNppGnnx_rRHb-bztNWAvzGQ"];
AVAsset *movieAsset = [AVURLAssetURLAssetWithURL:sourceMovieURL options:nil];
AVPlayerItem *playerItem = [AVPlayerItemplayerItemWithAsset:movieAsset];
self.playerItem = playerItem;
AVPlayer *player = [AVPlayerplayerWithPlayerItem:playerItem];
self.player = player;
AVPlayerLayer *playerLayer = [AVPlayerLayerplayerLayerWithPlayer:player];
playerLayer.frame = self.view.layer.bounds;
playerLayer.videoGravity =AVLayerVideoGravityResizeAspect;
[self.view.layeraddSublayer:playerLayer];
[self.playerplay];
注:1.AVPlayer本身是无法显示在界面上的,所以需要将其添加到View的layer上
2.AVPlayer能播放视频的格式有限,并不是所有的网络视频都能播放
简单demo:https://github.com/WLChopSticks/AVPlayerVideo/tree/master
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。