Appearance
lwlplayer
OpenHarmony 环境下可用的轻量级视频播放器,基于 FFmpeg 和 OHAudio,面向直播、点播和多 XComponent 渲染场景。
能力概览
- 支持直播、点播,直播支持 HLV、RTMP、RTSP 协议。
- 支持播放、停止、倍速、释放,倍速最高支持到 2 倍。
- 支持快进、后退、进度条与音量设置。
- 支持单 XComponent 和多 XComponent 渲染。
- 支持 FFmpeg 软解码,当前不支持硬解码。
安装
bash
ohpm install @lyzone/lwlplayer基本使用
ts
import { LwlPlayer, LwlPlayerType, LwlStreamPlayerCallback } from '@lyzone/lwlplayer'
private player: LwlPlayer = new LwlPlayer()
private controller: XComponentController | null = null
@State ptr: number = -1
private callback: LwlStreamPlayerCallback = {
onStatusChange: (status: number, msg: string): void => {
console.log(`playCallback: ${status}, msg: ${msg}`)
},
frameSize: (width: number, height: number): void => {
this.player.setFrameSize(width, height)
},
backProgress: (progress: number): void => {
console.log(`backProgress: ${progress}`)
}
}
aboutToAppear() {
this.controller = this.player.initLwlPlayerXComponentController(true)
this.ptr = this.player.createPlayer(LwlPlayerType.STREAM)
this.player.setPlayerCallback(this.ptr, this.callback)
}
aboutToDisappear() {
this.player.destroy(this.ptr, LwlPlayerType.STREAM)
}