当前位置:   article > 正文

视频播放–AVPlayer_免播放器av

免播放器av

视频播放–AVPlayer

  • 能播放本地、远程的音频、视频文件
  • 基于Layer显示,需要自己编写控制面板
#import <AVFoundation/AVFoundation.h>

-(AVPlayer *)player
{
    if(_palyer == nil){
        // 1.获取本地URL方式一
        NSString *filePath = [NSBundle mainBundle] pathForResource:@"welcome" ofType:@"mp4"];
        NSString *fileUrl = [NSURL fileURLWithPath:thePath];
        // 2.获取本地URL方式二
        NSURL *url = [[NSBundle mainBundle] URLForResource:@"welcome.mp4" wihtExtension:nil];
        // 3.获取远程URL方式
        NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/a45016f4-08d6-4277-abe6-bcfd5244c201/L.mp4"];

        // 4.创建AVPlayerItem
        AVPlayerItem *item = [AVPlayerItem playerItemWithURL:url];

        // 5.创建AVPlayer
        _player = [AVPlayer playerWithPlayerItem:item];

        // 6.添加AVPlayerLayer
        AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.player];
        layer.frame = CGRectMake(0,0,self.view.bounds.size.width,self.view.bounds.size.width *9 /16);
        [self.view.layer addSublayer:layer];
    }
    return _player;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 监听播放状态结束
 [[NSNotificationCenter defaultCenter] addObserver: selector:@selector(回调方法) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/282636
推荐阅读
相关标签
  

闽ICP备14008679号