3、投屏及播放控制
1)实例化播放器LBLelinkPlayer
实例化一个播放器LBLelinkPlayer,设置连接,设置代理,并使该类遵循代理协议LBLelinkPlayerDelegate。
self.player = [[LBLelinkPlayer alloc] init];
self.player.delegate = self;
self.player.lelinkConnection = self.lelinkConnection;
2)推送媒体
实例化播放器之后,就可以使用播放器将媒体投屏到接收端播放了。
推送媒体之前,先创建媒体对象。
// 实例化媒体对象
LBLelinkPlayerItem * item = [[LBLelinkPlayerItem alloc] init];
// 设置媒体类型
item.mediaType = LBLelinkMediaTypeVideoOnline;
// 设置媒体的URL
item.mediaURLString = @"https://devstreaming-cdn.apple.com/videos/wwdc/2017/602pxa6f2vw71ze/602/hls_vod_mvp.m3u8";
// 设置开始播放位置
item.startPosition = 0;
// 推送
[self.player playWithItem:item];
3)实现代理方法
播放状态、进度信息等在代理方法中回调出来,如果有需要可在代理方法中去变更UI。
#pragma mark - LBLelinkPlayerDelegate
// 播放错误代理回调,根据错误信息进行相关的处理
- (void)lelinkPlayer:(LBLelinkPlayer *)player onError:(NSError *)error {
if (error) {
NSLog(@"%@",error);
}
}
// 播放状态代理回调
- (void)lelinkPlayer:(LBLelinkPlayer *)player playStatus:(LBLelinkPlayStatus)playStatus {
NSLog(@"%d",playStatus);
// 根据状态设置播放器的UI
...
}
// 播放进度信息回调
- (void)lelinkPlayer:(LBLelinkPlayer *)player progressInfo:(LBLelinkProgressInfo *)progressInfo {
NSLog(@"current time = %d, duration = %d",progressInfo.currentTime,progressInfo.duration);
// 设置当前播放时间
self.currentTimeLabel.text = [NSString stringWithFormat:@"%ld",(long)progressInfo.currentTime];
// 设置总时间
self.durationLabel.text = [NSString stringWithFormat:@"%ld",(long)progressInfo.duration];
// 设置进度条
self.progressInfo.minimumValue = 0;
self.progressInfo.maximumValue = progressInfo.duration;
self.progressInfo.value = progressInfo.currentTime;
}
4)播放控制接口说明
以下是各种播放控制,需要的时候使用LBLelinkPlayer的实例直接调用。
/**
暂停播放
*/
- (void)pause;
/**
继续播放
*/
- (void)resumePlay;
/**
进度调节
@param seekTime 调节进度的位置,单位秒
*/
- (void)seekTo:(NSInteger)seekTime;
/**
退出播放
*/
- (void)stop;
/**
设置音量值
@param value 音量值,范围0 ~ 100
*/
- (void)setVolume:(NSInteger)value;
/**
增加音量
*/
- (void)addVolume;
/**
减小音量
*/
- (void)reduceVolume;
5)支持设置循环播放
设置LBLelinkPlayerItem的属性,可将当前推送的视频在接端上是否循环播放
/**
播放循环模式
*/
@property (nonatomic, assign) LBLelinkMediaPlayLoopMode loopMode;
//注意:当前版本仅支持LBLelinkMediaPlayLoopModeSingleCycle和LBLelinkMediaPlayLoopModeDefault
6)支持设置接收端播放器header
设置LBLelinkPlayerItem的属性,可设置接收端播放器的header
/**
播放器所需header信息, 以key-value的方式设置
*/
@property (nonatomic, strong) NSDictionary *headerInfo;
7)支持设置AES加密
设置LBLelinkPlayerItem的属性,用于视频加解密
/**
播放加密url地址所需的信息
*/
@property (nonatomic, strong) LBPlayerAesModel *aesModel;
/**
播放器地址播放所需的AES模型
*/
@interface LBPlayerAesModel : NSObject
/**
加密模式 ,默认:@"1"
*/
@property (nonatomic,copy) NSString *model;
/**
加密key,必填
*/
@property (nonatomic,copy) NSString *key;
/**
加密iv,必填
*/
@property (nonatomic,copy) NSString *iv;
@end