zoukankan      html  css  js  c++  java
  • MediaPlayer

    IOS系统的四层结构:核心操作系统层:Core OS,核心服务层:Core Services,媒体层:Media,Cocoa Touch层。

    使用MediaPlayer:

    1.引入MediaPlayer.frame框架,引入头文件#import <MediaPlayer/MediaPlayer.h>

    2.通过设置MPMoviePlayerViewController来设置全屏的播放:

      MPMoviePlayerController *_moviePlayer;

      MPMoviePlayerViewController *_mpMovieViewController;

    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"moxue" ofType:@"mp4"];//视频文件路径
        _mpMovieViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:filePath]];//将路径添加到MPMoviePlayerViewController
        [_mpMovieViewController.moviePlayer play];//设置moviePlayer播放
        [self.view addSubview:_mpMovieViewController.view];//将MPMoviePlayerViewController添加到view上。

    3.通过设置MPMoviePlayerController在view上设置播放屏幕的大小:

    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"moxue" ofType:@"mp4"];//视频文件路径
        _mpMovieViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:filePath]];//将路径添加到MPMoviePlayerViewController
     _moviePlayer = [_mpMovieViewController moviePlayer];//设置播放器
        _moviePlayer.view.frame = CGRectMake(50, 100, 300, 200);//设置播放器大小
       _moviePlayer.view.backgroundColor = [UIColor redColor];//设置背景颜色
        [_moviePlayer play];//播放
        [self.view addSubview:_moviePlayer.view];//添加到视图
        
        _moviePlayer.controlStyle = MPMovieControlStyleEmbedded;//控件选择
        _moviePlayer.scalingMode = MPMovieScalingModeAspectFit;//屏幕缩放

    4.设置播放器的一些监听方法:

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationObserver:) name:MPMoviePlayerDidEnterFullscreenNotification object:nil];//添加进入全屏的监听
    }
    -(void)notificationObserver:(NSNotification *)info
    {
        NSLog(@"%@",info);
    }
  • 相关阅读:
    课堂笔记-------字符串类型string------练习
    网络设计中需要考虑的时延latency差异
    ceph calamari 监控系统安装 on ubuntu 14.04
    Ceph性能优化总结(v0.94)
    创意点子
    “CEPH浅析”系列之八——小结
    “Ceph浅析”系列之七——关于Ceph的若干想法
    “CEPH浅析”系列之六——CEPH与OPENSTACK
    “Ceph浅析”系列之五——Ceph的工作原理及流程
    Ceph浅析”系列之四——Ceph的结构
  • 原文地址:https://www.cnblogs.com/moxuexiaotong/p/4988112.html
Copyright © 2011-2022 走看看