4-视频播放
- 1.Player
- 2.Setting the Rendering View
- 3.Playback Parameter Configuration
- 4.Playback Control
- 5.Callbacks
1.Player
The core external class of the player manager is PLVPlayerManager, which can be accessed via the playerManager property of the SDK object. The mainMediaPlayer inside playerManager is the player for video playback.
2.Setting the Rendering View
The player renders using an XComponent component of type surface, with the libraryname set to plvplayer_xcomponent. You can set the rendering view to the player using the startMainMediaPlayerWithComponent method:
XComponent({
id: `plvlw_video_xcomponent`,
type: "surface",
libraryname: "plvplayer_xcomponent"
}) {
}
.onLoad((component) => {
// 设置渲染画面并开始播放
this.sdk.playerManager.startMainMediaPlayerWithComponent(component!)
})
3.Playback Parameter Configuration
Set playback parameters by calling the setPlayerOption() method of mainMediaPlayer:
/**
* 设置播放参数
*/
setPlayerOption(options: PLVMediaPlayerOption[])
The PLVMediaPlayerOptionEnum class provides some commonly used playback parameters. You can directly reference its constants, for example:
// 开启精准seek的参数
PLVMediaPlayerOptionEnum.ENABLE_ACCURATE_SEEK.value("1")
For parameters that are set repeatedly, the newly set parameter will overwrite the old one. To clear a parameter, you can pass an empty string in the value field.
4.Playback Control
The player mainMediaPlayer provides a series of playback control interfaces, for example:
/**
* 开始播放
*/
start(): void;
/**
* 暂停播放
*/
pause(): void;`
/**
* 跳转播放进度到指定位置
* @param position 指定位置,单位:毫秒
*/
seek(position: number): void;
For more control operations, refer to IPLVMediaPlayer and its parent interface IPLVMediaPlayerControl.
5.Callbacks
Player status and event callbacks can be monitored through the callback registration center, including:
- IPLVMediaPlayerBusinessListenerRegistry: Player business callback registration center
- IPLVMediaPlayerEventListenerRegistry: Player event callback registration center
- IPLVMediaPlayerStateListenerRegistry: Player state callback registration center
To monitor the play/pause state, for example, you can do so in the following way:
const playingState: MutableState<PLVMediaPlayerPlayingState> = player.getStateListenerRegistry().playingState;
const observer = playingState.observe((state: PLVMediaPlayerPlayingState) => {
// 处理逻辑
const isPlaying = state === PLVMediaPlayerPlayingState.PLAYING;
});
