文档

直播播放器

更新时间:
一键部署

本文介绍iOS应用端,直播播放器的使用流程。

使用流程

  1. 创建直播播放器。

  2. 配置播放器的渲染窗口并设置播放器回调。

  3. 按需配置播放器的其他参数。例如:软硬解码偏好、视频画面模式等。

  4. 调用QueryLiveStreaming接口获取IPC设备的直播开播rtmp播放地址,并作为数据源设置给播放器。

  5. 开始播放。

  6. 停止播放。

  7. 销毁直播播放器。

使用示例

// 构造播放器实例
self.player = [[LVLivePlayer alloc] init];
// 设置必要的监听
self.player.livePlayerDelegate = self;
...
    
#pragma mark LVLivePlayerDelegate
- (void) onLivePlayerError:(LVLivePlayer *_Nonnull)player error:(NSError *_Nonnull)error{
    [self appendInfoText:[NSString stringWithFormat:@"播放出错: %@\n", error]];
}

- (void) onLivePlayerStateChange:(LVLivePlayer *_Nonnull)player playerState:(LVPlayerState)state{
    [self appendInfoText:[NSString stringWithFormat:@"状态变更: %d\n", state]];
}

- (void) onLivePlayerRenderedFirstFrame:(LVLivePlayer *_Nonnull)player elapsedTimeInMs:(NSInteger)elapsedTimeInMs{
    [self appendInfoText:[NSString stringWithFormat:@"首帧出图耗时: %ldms\n", (long)elapsedTimeInMs]];
    [self appendInfoText:[self.player getStatisticsInfo]];
}

- (void) onLivePlayerVideoSizeChanged:(LVLivePlayer *_Nonnull)player width:(NSInteger)width height:(NSInteger)height{
    [self appendInfoText:[NSString stringWithFormat:@"图像大小变化: w=%ld h=%ld\n", (long)width, (long)height]];
}

- (void) onLivePlayerStandardSeiInfoUpdate:(LVLivePlayer *_Nonnull)player sei:(NSData*_Nonnull)data timeStamp:(NSInteger)timeStamp{
    [self appendInfoText:[NSString stringWithFormat:@"sei: %lu %ld\n", (unsigned long)data.length, timeStamp]];
}

- (void) onLivePlayerVideoJitterBufferEmpty:(LVLivePlayer *_Nonnull)player{
}
...
// 创建LVGlkView,放在scrollview中具备画面缩放能力
self.lvGlkView = [[LVGlkView alloc] initWithFrame:CGRectMake(0,0,self.scrollView.frame.size.width, self.scrollView.frame.size.height)];;
[self.scrollView addSubview:self.lvGlkView];
[self.lvGlkView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerX.equalTo(@(0));
    make.centerY.equalTo(@(0));
    make.height.equalTo(self.scrollView.mas_height);
    make.width.equalTo(self.scrollView.mas_width);
}];
// 为播放器设置用于画面渲染的窗口, 画面不做旋转
[self.player setWindow:self.lvGlkView videoRotationMode:LV_MEDIA_VIDEO_ROTATE_0_CLOCKWISE];

...
// 设置数据源,rtmp地址从云服务获取
[self.player setDataSource:@"rtmp://xx.xx.xx.xx/live/xxx"isEncrypted:(YES) decryptIvBase64:(@"xxxxxxx") decryptKeyBase64:@"xxxxxxx"];

// 设置解码策略为硬解码优先
[self.player setDecoderStrategy:LV_DECODER_STRATEGY_HARDWARE_FIRST];
// 设置画面模式为保持宽高
[self.player setVideoScalingMode:LV_MEDIA_VIDEO_SCALING_MODE_FIT];
// 设置播放停止时画面保留最后一帧
[self.player setPlayerStoppedDrawingMode:LV_PLAYER_STOPPED_DRAWING_MODE_ALWAYS_KEEP_LAST_FRAME];
...
// 开始播放
[self.player start];
...
// 停止播放
[self.player stop];
  • 本页导读 (1)
文档反馈