快速开始
集成准备
权限要求
[{
"name": "ohos.permission.MICROPHONE",
"reason": "$string:mic_reason",
"usedScene": {
"abilities": ["EntryAbility"],
"when": "inuse"
}
}, {
"name": "ohos.permission.CAMERA",
"reason": "$string:mic_reason",
"usedScene": {
"abilities": ["EntryAbility"],
"when": "inuse"
}
}, {
"name": "ohos.permission.INTERNET",
"reason": "$string:network",
"usedScene": {
"abilities": ["EntryAbility"],
"when": "inuse"
}
}]
下载安装
- 安装依赖
ohpm install @qiniu/pl-media-streaming
- 打开项目的 oh-package.json5 文件,查看 PLMediaStreaming 的引用
使用方法
// QComponent 为内部封装过的 xComponent 组件,用于预览本地摄像头
import { MediaStreamingManager, QComponent, XComponentContext } from '@qiniu/pl-media-streaming'
const audioProfile = new AudioProfile(this.audioEncodingSampleRate, this.audioEncodingBitRate * 1024)
const videoProfile = new VideoProfile(this.videoEncodingFPS, this.videoEncodingBitrate * 1024, this.maxFPSInterval, this.videoEncodingProfile)
const avProfile = new AVProfile({ videoProfile: this.videoProfile, audioProfile: this.audioProfile })
const profile = new StreamingProfile()
.setAVProfile(this.avProfile)
.setVideoEncodeType(this.encodingType)
.setPublishUrl(this.rtmpUrl)
const cameraStreamingSetting = new CameraStreamingSetting()
const microphoneStreamingSetting = new MicrophoneStreamingSetting()
QComponent({
ratio: this.cameraRatio,
aspectType: this.aspectType,
onLoad: async (xComponentContext) => {
this.xComponentContext = xComponentContext as XComponentContext
await this.streamingManager?.prepare(this.profile, this.microphoneStreamingSetting, this.xComponentContext, this.cameraStreamingSetting)
await this.streamingManager?.startStreaming()
}
})
文档反馈
(如有产品使用问题,请 提交工单)