当前位置:   article > 正文

AVPlayer实现视频播放功能_av看视频

av看视频

    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


声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号