• IOS 播放视频(MPMoviePlayerController、MPMoviePlayerViewController)


    iOS提供了叫 做MPMoviePlayerControllerMPMoviePlayerViewController的两个 类,可以用来轻松播放视频

     ➢ YouTobe就是用MPMoviePlayerController实现的 MPMoviePlayerViewController只能全屏播放视频

    上述两个类都定义在了MediaPlayer框架中

     
     
     

    MPMoviePlayerController-01-加载资源

     // 加载视频资源
    NSString *urlString = [[NSBundle mainBundle]

    pathForResource:@"sample_iTunes" ofType:@"mov"];
    
    NSURL *url = [NSURL fileURLWithPath:urlString];
    

    // 创建播放器

    _player = [[MPMoviePlayerController alloc]
    initWithContentURL:url];

    // 加载视频资源
    NSString *urlString = [[NSBundle mainBundle]
    pathForResource:@"sample_iTunes" ofType:@"mov"];
    NSURL *url = [NSURL fileURLWithPath:urlString];
    

    // 创建播放器

    _player = [[MPMoviePlayerController alloc]
    initWithContentURL:url];
    

    MPMoviePlayerController-02-显示

    // 设置尺寸
    _player.view.frame = self.view.bounds;
    _player.view.autoresizingMask =UIViewAutoresizingFlexibleWidth |
    UIViewAutoresizingFlexibleHeight;
    

    // 添加到控制器的view
    [self.view addSubview:_player.view]; // 播放
    [_player play];

    MPMoviePlayerController-03-添加通知监听
    // 监听播放状态的改变

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoStateChange)

    name:MPMoviePlayerPlaybackStateDidChangeNotification object:_player];
    

    // 监听播放器结束全屏

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitFullscreen)
    name:MPMoviePlayerDidExitFullscreenNotification object:_player];
    

    MPMoviePlayerController其他属性

    是否要自动播放
    @property(nonatomic) BOOL shouldAutoplay;

    全屏显示
    @property(nonatomic, getter=isFullscreen) BOOL

    fullscreen;
    - (void)setFullscreen:(BOOL)fullscreen animated:
    

    (BOOL)animated;

    截取视频中的图片

    - (void)requestThumbnailImagesAtTimes:(NSArray
    *)playbackTimes timeOption:(MPMovieTimeOption)option;
    

     

    MPMoviePlayerViewController

    MPMoviePlayerViewController继承自UIViewController,它内部封装了一 个MPMoviePlayerController

    MPMoviePlayerViewController只能全屏播放

    简单使用:

    MPMoviePlayerViewController *play =
    [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    
    其他
    音频处理
    依赖的框架:AVFoundationAudioToolbox框架
    播放长音乐:AVAudioPlayer
    播放短音效:加载音频文件生成SystemSoundID
    录音:AVAudioRecord
     

     ● 较为底层、高级的音频视频处理

    CoreAudioCoreVideo框架

     

     
    
    
  • 相关阅读:
    General part中方向选取的作用
    mount part中位置的作用
    关于zero pivot
    Revit二次开发示例:ModelessForm_ExternalEvent
    elasticsearch6.4 memory locking requested for elasticsearch process but memory is not locked
    百度网盘 http://pandownload.com/index.html
    MySQL 5.7主从复制从零开始设置及全面详解——实现多线程并行同步,解决主从复制延迟问题!
    linux 系统优化
    服务器cpu过高修复:操作系统内核bug导致
    Jvm中时区设置方式
  • 原文地址:https://www.cnblogs.com/liuwj/p/6701486.html
Copyright © 2020-2023  润新知