产品详细信息
商品详情
NodeMediaClient-Harmony
NodePlayer 组件
OpenHarmony_5.0 / HarmonyOS_NEXT 平台的低延迟直播播放组件
特性
- 支持RTSP,RTMP(S),HTTP(S)_FLV,HLS,KMP,UDP_MPEGTS等协议。
- 支持H.264/H.265视频硬件解码渲染
- 支持AAC/G.711音频解码播放
- 毫秒级低延迟
- 延迟消除
安装依赖
使用DevEco打开项目后,点击下方Terminal,输入命令安装依赖
ohpm install @nodemedia/nodemediaclient
引用播放组件
import { router } from '@kit.ArkUI';
import { NodePlayer, NodePlayerController } from '@nodemedia/nodemediaclient';
@Entry
@Component
struct VideoViewPage {
@State src: string = 'rtmp://192.168.0.2/live/bbb';
// @State src: string = 'https://192.168.0.2:8443/live/bbb.flv';
// @State src: string = 'rtsp://admin:admin@192.168.0.11:554/Streaming/channels/101';
@State volume: number = 1.0;
@State muted: boolean = false;
@State bufferTime: number = 1000;
@State scaleMode: number = 0;
private license: string = '';
private controller: NodePlayerController = new NodePlayerController();
build() {
Column() {
Button("Back").onClick(() => {
router.back()
})
NodePlayer({
license: this.license,
src: this.src,
scaleMode: this.scaleMode,
bufferTime: this.bufferTime,
controller: this.controller,
muted: this.muted,
volume: this.volume,
autoplay: true,
onEvent: (code: number, msg: string) => {
console.info('NodePlayer on event, code:' + code, 'message:' + msg);
}
})
.width('100%')
.height('40%')
.margin({ bottom: '10' })
TextInput({ text: this.src })
.onChange((v) => {
this.src = v;
})
.margin({ bottom: '10' })
Row() {
Text("Muted")
Toggle({ type: ToggleType.Switch, isOn: this.muted }).onChange((v) => {
this.muted = v;
})
}
Row() {
Text("Volume")
Slider({
max: 1.0,
min: 0.0,
step: 0.1,
value: this.volume
}).onChange((v, mode) => {
this.volume = v;
this.muted = false;
}).width('60%')
Text(this.volume.toString().slice(0, 3))
}.margin(10)
Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
Text("ScaleMode")
Column() {
Text('0')
Radio({ value: 'Radio1', group: 'radioGroup' }).checked(this.scaleMode == 0)
.height(30)
.width(30)
.onChange((isChecked: boolean) => {
this.scaleMode = 0;
})
}
Column() {
Text('1')
Radio({ value: 'Radio2', group: 'radioGroup' }).checked(this.scaleMode == 1)
.height(30)
.width(30)
.onChange((isChecked: boolean) => {
this.scaleMode = 1;
})
}
Column() {
Text('2')
Radio({ value: 'Radio3', group: 'radioGroup' }).checked(this.scaleMode == 2)
.height(30)
.width(30)
.onChange((isChecked: boolean) => {
this.scaleMode = 2;
})
}
}.margin({ bottom: '10' })
Row() {
Button("开始播放")
.onClick(() => {
this.controller.start()
})
Button("停止播放")
.onClick(() => {
this.controller.stop()
})
Button("暂停播放")
.onClick(() => {
this.controller.pause()
})
}
}
.padding('10')
}
}
申请网络权限
"requestPermissions": [
{
"name": "ohos.permission.INTERNET"
}
],
提示
请输入正确的应用程序ID,HarmonyOS为bundleName。
离线授权码,授权后无法修改,绑定应用程序ID,授权到2099年。