118 系统视频播放

1.AVPlayer播放本地和远程

- (void)avPlayer
{
    //NSURL *url = [[NSBundle mainBundle] URLForResource:@"minion_01.mp4" withExtension:nil];
    NSURL *url = [NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
    // 创建播放器
    AVPlayer *player = [AVPlayer playerWithURL:url];
    [player play];

    // 创建播放器图层
    AVPlayerLayer *layer = [AVPlayerLayer layer];
    layer.player = player;
    layer.frame = CGRectMake(10, 0, 300, 200);

    // 添加图层到控制器的view
    [self.view.layer addSublayer:layer];
    self.player = player;
}

2.MPMoviePlayerController视频播放(无界面)

- (void)moviewPlayerController
{
    // 创建播放器对象(属性直接赋值,不是属性会黑屏)
    self.mpc = [[MPMoviePlayerController alloc] init];
    // 设置URL
    //self.mpc.contentURL = [[NSBundle mainBundle] URLForResource:@"minion_01.mp4" withExtension:nil];
      self.mpc.contentURL = [NSURL URLWithString:@"http://streams.videolan.org/streams/mp4/Mr_MrsSmith-h264_aac.mp4"];

    // 添加播放器界面到控制器的view上面
    self.mpc.view.frame = CGRectMake(10, 50, 300, 200);
    [self.view addSubview:self.mpc.view];

    [self.mpc play];


    // 隐藏自动自带的控制面板
    self.mpc.controlStyle = MPMovieControlStyleNone;

    // 监听播放器
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDidFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:self.mpc];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieStateDidChange) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.mpc];

}

3.MPMoviePlayerViewController(有界面)

- (void)moviewPlayerViewController
{
    //NSURL *url = [[NSBundle mainBundle] URLForResource:@"minion_01.mp4" withExtension:nil];
    NSURL *url = [NSURL URLWithString:@"http://y1.eoews.com/assets/ringtones/2012/5/18/34045/hi4dwfmrxm2citwjcc5841z3tiqaeeoczhbtfoex.mp3"];
    MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    [self presentMoviePlayerViewControllerAnimated:mpvc];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值