Joe
10 months ago
3 changed files with 50 additions and 12 deletions
@ -0,0 +1,41 @@ |
|||||
|
import flvJs from "flv.js"; |
||||
|
import { getCameraStream } from "@screen/pages/Home/components/RoadAndEvents/utils/httpList.js"; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @param {HTMLElement} container 容器 |
||||
|
* @param {{camId?: string; url?: string}?} options {camId: 相机ID; url: 直播地址} |
||||
|
* @returns |
||||
|
*/ |
||||
|
export async function openVideoStream(container, { camId, url } = {}) { |
||||
|
if (camId) { |
||||
|
const { code, data } = await getCameraStream(camId).catch(() => ({})); |
||||
|
|
||||
|
if (code != 200) return; |
||||
|
|
||||
|
url = data.liveUrl; |
||||
|
} |
||||
|
|
||||
|
if (!url) return; |
||||
|
|
||||
|
const flvPlayer = flvJs.createPlayer({ |
||||
|
type: "flv", |
||||
|
url: url, |
||||
|
isLive: true, |
||||
|
hasVideo: true, |
||||
|
hasAudio: true, |
||||
|
}); |
||||
|
|
||||
|
console.log( |
||||
|
"%c [ flvPlayer ]-26-「videoStream.js」", |
||||
|
"font-size:15px; background:#b2b540; color:#f6f984;", |
||||
|
flvPlayer |
||||
|
); |
||||
|
|
||||
|
flvPlayer.attachMediaElement(container); |
||||
|
|
||||
|
flvPlayer.load(); |
||||
|
flvPlayer.play(); |
||||
|
|
||||
|
return flvPlayer; |
||||
|
} |
Loading…
Reference in new issue