做视频开发的作者最近看到网上出现一个叫轻骑兵播放器的SDK,研究了下发现API很简洁,调用蛮方便的,关键还是免费使用。便在其官网注册个账号,下载了SDK,准备做一个小DEMO看看性能,因为该SDK才推出不久,网上还没看到方法用例,作者就分享下自己的集成过程。
1.创建工程
在官网下载SDK,是一个动态库framework,需要用Embedded Binaries加到工程
589aee85b941bd2225000001.png
3.添加必要的framework
589aeecab941bd2225000002.png
4.注册应用
589aef41b941bd2225000003.png
589aef6cb941bd2225000004.png
5.APP启动注册SDK
在AppDelegate.m文件中输入key和用户名
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [Hussarkey:@"C5l3F7NTcSND3IzpSSKagMyfJPfRvOMa/yr3LgltFykTyRi57MVEGovyQR4="UserName:@"demo@demo.com"];returnYES;}
6.播放器调用代码
//// ViewController.m// TestHussar//// Created by Tester on 2017/1/22.// Copyright © 2017年 Hussar. All rights reserved.//#import"ViewController.h"#import@interfaceViewController()@property(nonatomic,strong) HussarPlayerViewController *player;@property(weak,nonatomic)IBOutletUIView*playerview;@end@implementationViewController- (void)viewDidLoad { [superviewDidLoad];}- (void)viewDidAppear:(BOOL)animated{ [superviewDidAppear:animated]; [selfplayURL:[NSURLURLWithString:@"http://120.25.226.186:32812/resources/videos/minion_01.mp4"]];}- (void)playURL:(NSURL*)url{self.player = [[HussarPlayerViewController alloc]initWithURL:url];self.player.delegate =self;self.player.view.frame =self.playerview.bounds; [self.playerview addSubview:self.player.view];}- (void)dealloc{ [self.player stop];}#pragma mark - HussarPlayerViewControllerDelegate/**
已加载完毕事件
*/- (void) onPrepared{NSLog(@"onPrepared");}/**
开始渲染第一帧事件
*/- (void) onRenderStart{NSLog(@"onRenderStart");}/**
开始播放事件
*/- (void) onStart{NSLog(@"onStart");}/**
暂停播放事件
*/- (void) onPause{NSLog(@"onPause");}/**
开始缓冲事件
@param type HussarBufferType 卡顿类型
*/- (void) onBufferingStart:(HussarBufferType)type{NSLog(@"onBufferingStart");}/**
缓冲中事件
@param percent 缓冲百分比
*/- (void) onBuffering:(int)percent{NSLog(@"onBuffering");}/**
缓冲结束事件
*/- (void) onBufferingEnd{NSLog(@"onBufferingEnd");}/**
seek结束事件
@param position seek到最新的位置
*/- (void) onSeekComplete:(int)position{NSLog(@"onSeekComplete");}/**
播放完成事件
*/- (void) onCompletion{NSLog(@"onCompletion");}- (void)updateHussarTime{NSLog(@"updateHussarTime:%f,%f",self.player.playbackTime,self.player.duration);}/**
播放报错信息
@param what 错误主类
@param extra 错误详细类别
@return 是否需要停止播放,仅对非严重错误有效
*/- (BOOL) onError:(int)what Extra:(int)extra{NSLog(@"onError");returnNO;}/**
按钮事件回调
@param buttonEvent 按钮类型
@param info 按钮附带信息
*/- (void)hussarPlayerButtonEvent:(HussarPlayerButtonEvent)buttonEvent Info:(NSDictionary*)info{}@end
7.运行APP