博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MCPlayerKit 易用的播放组件,通用播放器
阅读量:7050 次
发布时间:2019-06-28

本文共 5038 字,大约阅读时间需要 16 分钟。

当写下2019·时,时间的匆忙扑面而来,愿每一天是美好的一天。

MCPlayerKit

MCPlayerKit 介绍

从事移动端开发以来,一直在做音视频类的开发,苹果的播放器基本定制型太强,需要定制在开源有kxmovie,授权的vitamio等,但层次不一,经过几年的发展,尤其是在这两年直播等投资热的趋势下,音视频技术逐渐趋于成熟,随便找几个库就能解决燃眉之急,开源的力量更进一步的推进了技术的发展,我也想写个简单的项目,写出一些心得。

是基于AVPlayer和IJKPlayer做的一款播放内核播放模块,做IJKPlayer支持是因为AVPlayer对于一些格式协议的支持的补充,比如flv、RTMP等。

特点

  • PlayerKit高度抽象出播放层和渲染层
  • 耦合低,使用方便
  • 有很多使用案例

Installation

Installation with CocoaPods

To integrate MCPlayerKit into your Xcode project using CocoaPods, specify it in your Podfile: 如果纯使用MCPlayerKit播放功能,请用

pod 'MCPlayerKit/Core' or pod 'MCPlayerKit'复制代码

如果需要使用高度通用UI的,可以用

pod 'MCPlayerKit/GeneralPlayerUI'复制代码
GeneralPlayerUI 样式依赖于'MCStyle',Example/Classes/Modules/GeneralPlayer/MCPlayerGeneralController有他的详细使用,你可以通过json配置GeneralPlayerUI颜色、样式、字体等。复制代码

Run pod install

使用方法

1. 纯播放功能,自定义UI

1.1 功能

a. support AVPlayer & IJKPlayer    b. 统一渲染页面复制代码

1.2 接入代码

- (MCPlayerKit *)playerKit {    if (!_playerKit) {        _playerKit = [[MCPlayerKit alloc] initWithPlayerView:self.playerView];        _playerKit.playerCoreType = PlayerCoreAVPlayer;        _playerKit.playerStatusDelegate = self;    }    return _playerKit;}//自定义渲染界面- (MCPlayerView *)playerView {    if (!_playerView) {        CGFloat width = MIN([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);        CGFloat height = width * 9 / 16.0f;        _playerView = [[MCPlayerView alloc] initWithFrame:CGRectMake(0, 0, width, height)];    }    return _playerView;}[self.playerKit playUrls:@[@"http://aliuwmp3.changba.com/userdata/video/45F6BD5E445E4C029C33DC5901307461.mp4"]];复制代码

2.GeneralPlayerUI 通用播放器UI

2.1 功能

a. 旋转    b. support 2018 Devices    c. loading    b. 播放中断重试    c. 用户可以自定义UI颜色、样式、字体大小TODO:    I. 投屏UI复制代码

2.2 接入代码

//颜色配置    [MCStyleManager share].colorStyleDataCallback = ^NSDictionary *(void) {        NSString *path = [[NSBundle mainBundle] pathForResource:@"CustomPlayerColor" ofType:@"json"];        NSError *error;        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableContainers error:&error];        NSAssert(!error, @"read json file error");        return dictionary[@"data"];    };    //字体样式配置    [MCStyleManager share].fontStyleDataCallBack = ^NSDictionary *(void) {        NSString *path = [[NSBundle mainBundle] pathForResource:@"CustomPlayerFont" ofType:@"json"];        NSError *error;        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableContainers error:&error];        NSAssert(!error, @"read json file error");        return dictionary[@"data"];    };    //图片等配置    [MCStyleManager share].styleDataCallback = ^NSDictionary *(void) {        NSString *path = [[NSBundle mainBundle] pathForResource:@"CustomPlayerStyle" ofType:@"json"];        NSError *error;        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableContainers error:&error];        NSAssert(!error, @"read json file error");        return dictionary[@"data"];    };    [[MCStyleManager share] loadData];    [self.view addSubview:self.playerView];    [self.playerView updatePlayerPicture:@"https://avatars0.githubusercontent.com/u/3861387?s=460&v=4"];    [self.playerView updateTitle:@"Skipping code signing because the target does not have an Info.plist file. (in target 'App')"];//    [self.playerKit playUrls:@[@"http://aliuwmp3.changba.com/userdata/video/45F6BD5E445E4C029C33DC5901307461.mp4"]];    [self.playerKit playUrls:@[@"http://aaaaaliuwmp3.changba.com/userdata/video/45F6BD5E445E4C029C33DC5901307461.mp4"]];    [self.playerView updateAction:self.playerKit];    self.playerView.retryPlayUrl = ^NSString *(void) {        return @"http://aliuwmp3.changba.com/userdata/video/45F6BD5E445E4C029C33DC5901307461.mp4";    };        - (MCPlayerKit *)playerKit {        if (!_playerKit) {            _playerKit = [[MCPlayerKit alloc] initWithPlayerView:self.playerView.playerView];            _playerKit.playerCoreType = PlayerCoreAVPlayer;        }        return _playerKit;    }        - (MCPlayerGeneralView *)playerView {        if (!_playerView) {            CGFloat width = MIN([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);            CGFloat height = width * 9 / 16.0f + [MCDeviceUtils xTop];            _playerView = [[MCPlayerGeneralView alloc] initWithFrame:CGRectMake(0, 0, width, height)];        }        return _playerView;    }        具体参照 Example/Classes/Modules/GeneralPlayer/MCPlayerGeneralController复制代码

2.3 Screenshot

类结构

PlayerKit --------------- 播放器核心,AVPlayer与IJKPlayer抽象    -- Core               Player抽象与实现以及PlayerKit播放器控制    -- Extend             辅助类    -- PlayerView         播放器界面父类,Custom播放器界面View必须继承与此类    GeneralPlayerUI----------- 通用播放组件UI    -- Views               通用UI subviews    -- MCPlayerGeneralView 通用播放界面Commen ------------------- 通用类复制代码

more

此项目会作为长期维护项目,接受各位指导。

License

These PlayerKit are available under the MIT license.

转载地址:http://orpol.baihongyu.com/

你可能感兴趣的文章
有价值的数据
查看>>
LayUi超级好用的前端工具
查看>>
[Ubuntu] ubuntu的tty下挂载移动硬盘拷贝数据
查看>>
犯了个低级错误
查看>>
Outlook Anywhere 客户端配置详解
查看>>
IOS在Xcode 4.x以上如何 创建 和 添加 静态库
查看>>
Repeater控件数据导出Excel
查看>>
下载Android源码出现的问题
查看>>
远程桌面如何复制本地文件 远程桌面拷贝电脑上的文件方法
查看>>
[转]解决JS浮点数(小数)计算加减乘除的BUG
查看>>
ASP.NET MVC应用程序的安全性介绍总括(高级编程)
查看>>
记录下,我们平时开发当中不得不知道的HTTP状态码
查看>>
HDU-1045 Fire NetFire Net 最大团
查看>>
Eclipse自动部署项目到Tomcat的webapps下的有效方法
查看>>
Extjs4快速上手三——实现主界面
查看>>
如何替代Flex?
查看>>
控制属性修改时间,控制时间,联合主键
查看>>
android-包签名
查看>>
Android开发和调试必备工具-SDK Tools
查看>>
《微软的软件测试之道》读书笔记 之 结构测试技术
查看>>