| 类名 | 描述 |
|---|---|
| VHWatchVodPlayer | 播放器控制核心类 |
| VHWatchVodPlayerView | 播放器核心组件 |
| VHWatchVodPlayerCallback | 播放器事件回调 |
暖场视频用于在预约或直播前未开播的活动显示用户预设的视频。暖场视频配置通过调用初始化接口返回的VHWebinarData.VHWarmup类。并且满足部分条件才能进行观看。具体参考VHWarmup说明。
//是否满足暖场视频播放条件
private isEnablePlay(advance_play_time: number): boolean {
if (advance_play_time == 0) {
return true;
}
let date = new Date(this.webinar_info?.webinar?.start_time!);
let milliseconds = date.getTime();
let current = systemDateTime.getTime();
//未到开播时间
if (current <= milliseconds) {
let diff = milliseconds - current;
// 暖场视频播放
if (diff / 1000 < advance_play_time) {
return true;
} else {
return false;
}
}
//已经超过开播时间不播放暖场视频
return false;
}
//判断是否有暖场视频
if (this.webinar_info && this.webinar_info.warm_up) {
if (this.isEnablePlay(this.webinar_info.warm_up.advance_play_time)) {
Column() {
//构建暖场视频播放器
VHWarmPlayerView({ webinars: this.webinar_info, player_config: this.player_config })
.width('100%')
.height('100%')
}
.width('100%')
.flexShrink(0)
.zIndex(2)
.height('100%')
}
}
import { VHWatchVodPlayer} from "@vhall/vhall_live";
@Component
export struct VHWatchLivePlayerComponent {
@State message: string = 'Hello World';
/**
* 播放器控制类
* */
public vodPlayer?: VHWatchVodPlayer = new VHWatchVodPlayer(this.getUIContext().getHostContext() as Context);
......
}@Component
export struct VHWatchVodPlayerView {
/**
* 组件状态更新回调
*/
@Require public componentListener?: VHWatchVodPlayerCallback;
/**
* 播放器控制类
* */
@Require public vodPlayer?:VHWatchVodPlayer;
/**
* 控制是否扩展
*/
@Prop public is_expand: boolean = false;
/**
* @param enable_default_water_mask 是否使用默认水印
* **/
@Require enable_default_water_mask:boolean = false;
/**
* @param water 水印
* **/
@Require water: VHWatermarkConfig | null = null;
} build() {
Stack({ alignContent: Alignment.Center }) {
// 播放器容器
VHWatchVodPlayerView({
componentListener: this,
vodPlayer: this.vodPlayer,
is_expand: this.is_expand,
enable_default_water_mask: true,
water: this.player_config?.water
})
.width('100%')
.height('100%')
.expandSafeArea(this.is_expand ? this.expandTypes : [], this.is_expand ? this.expandEdges : [])
.backgroundColor(Color.Black)
.align(Alignment.Center)
.zIndex(playerZIndex.indexOf(PLAYER_INDEX))
}
} public initWebinarInfo(webinarsInfo: VHWebinarData)| 参数名称 | 是否必须 | 示例 | 备注 |
|---|---|---|---|
| webinarsInfo | 是 | xx | 活动信息 |
| 代码示例 |
aboutToAppear(): void {
this.vodPlayer?.initWebinarInfo(this.webinars!);
} public setLivePlayerListener(listener: VHWatchLivePlayerCallback)
@Component
export struct VHWatchVodPlayerComponent {
public vodPlayer?: VHWatchVodPlayer = new VHWatchVodPlayer(this.getUIContext().getHostContext() as Context);
@State public webinars: VHWebinarData | null = null;
aboutToAppear(): void {
//初始化播放器活动信息
this.vodPlayer?.initWebinarInfo(this.webinars!);
//是否支持画中画
if (this.player_config?.basic?.picture_in_picture == 1) {
this.vodPlayer?.initPipController(true);
}
this.vodPlayer?.setVodPlayerListener(this);
this.vodPlayer?.setPlayerScalingMode(VHPlayerVideoScalingMode.VH_ASPECT_FILL);
}
} public startPlayWithRecordId(paas_record_id:string,def:VHPlayDefinition)| 参数名称 | 是否必须 | 示例 | 备注 |
|---|---|---|---|
| paas_record_id | 是 | xx | 回放id,通过初始化接口获取到warmup_paas_record_id数组得到回放id, |
| def | 是 | xx | 清晰度 |
//组件初始化成功后播放暖场视频
onPlayerViewInitCompleted(){
if( this.currentPlayId.length > 0){
this.vodPlayer?.startPlayWithRecordId(this.currentPlayId,this.player_config?.default_definition!);
this.isPlayError = true;
}
} public stopPlay() this.vodPlayer?.stopPlay(); public pausePlay() //控制暂停和恢复
if(this.is_playing){
this.vodPlayer?.pausePlay();
this.vodPlayer?.updatePipControlStatus(VHPipControlPanelStatus.VH_CONTROL_PAUSE);
}else{
this.vodPlayer?.resumePlay();
this.vodPlayer?.updatePipControlStatus(VHPipControlPanelStatus.VH_CONTROL_PLAY);
}