iOS 视频播放

  • 这是一个使用简便的视频播放框架,它基于UIView,它可以是一个小窗口,也可以是一个全屏的窗口
  • 简单的方式加载Video框架: 一行代码加载! 一行代码更新!

  • 下载链接 : https://github.com/huyp/YVideoPlayer

功能

  • 支持本地视频&网络视频
  • 开始&暂停
  • 最大化&还原
  • 图像左侧上下调节 : 亮度 
  • 图像右侧上下调节 : 音量
  • 左右滑动 : 快进快退

简介

  • 这是一个UIView的子类,它可以加载到你所需要的任何位置.
  • 它可以是一个小窗口,也可以是一个全屏的窗口
  • 支持方向识别,横屏时自动最大化

使用

加载:

导入头文件
#import "YVideoPlayerView.h"
yVideoPlayerView = [YVideoPlayerView initWithVideoName:@"视频名称1" frame:CGRectMake(0,20,200,150) path:@"http://videoPath" onViewControll:self];

初始化方法
+ (instancetype)initWithVideoName:(NSString *)name frame:(CGRect)frame path:(NSString *)path onViewControll:(UIViewController *)OnViewController;

name : 视频名称
frame : 视频位置
path : 视频路径
onViewController : 加载视频所在的ViewController -> 一般写self

更新:

yVideoPlayerView = [yVideoPlayerView updateVideoWithName:@"视频名称2" path:@"http://videoPath2" onViewController:self];

注意 : 这是一个对象方法
- (instancetype)updateVideoWithName:(NSString *)name path:(NSString *)path onViewController :(UIViewController *)OnViewController;

name : 视频名称
path : 视频路径
onViewController : 加载视频所在的ViewController -> 一般写self

这里不用重写frame -- 参照了初始化时

提醒

  • 本框架纯ARC,兼容的系统>=iOS6.0、iPhoneiPad横竖屏
  • 横竖屏需要手机关闭横竖排方向锁定
  • App至少要开启LandScape Left 或 LandScape Right其中的一项. 如App其他页面不能转屏,用代码锁定!
    • 在其他不需要转屏的根视图里写如下代码:
      - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
            return UIInterfaceOrientationMaskPortrait;
        }
    • 在加载YVideoPlayerView的ViewController里写如下代码:
      //只让这个页面转动
        - (BOOL)shouldAutorotate {
            return YES;
        }
        - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
            if (yVideoPlayerView.canOrientationChange == YES) {  //刚进入页面是竖屏
                return UIInterfaceOrientationMaskAllButUpsideDown;
            }
            return UIInterfaceOrientationMaskPortrait;
        }
原文地址:https://www.cnblogs.com/huyp/p/5377553.html