diff --git a/example/dist/dist-play.js b/example/dist/dist-play.js index 814eaba2..0d8680aa 100644 --- a/example/dist/dist-play.js +++ b/example/dist/dist-play.js @@ -488,278 +488,6 @@ global.makeH265webjs = function (videoURL, config) { } }; - playerObj["do"](); - return playerObj; -}; -/*************************************************** - * - * - * - * 2. RAW HEVC DEMO - * HEVC/H.265, Demo for VOD, 点播文件播放demo - * - * - * - ***************************************************/ - - -var workerFetch = new Worker('./dist/worker-fetch-dist.js'); -var workerParse = new Worker('./dist/worker-parse-dist.js'); -console.log("workerFetch:", workerFetch); -console.log("workerParse:", workerParse); -/* - * 创建265流播放器 - */ - -global.makeH265webjsRaw = function (url265, config) { - var playerId = config.player; - - var playerObj = _index["default"].createPlayer(null, config); - - var playerDom = document.querySelector('#' + playerId); - var playerCont = document.querySelector('#player-container'); - var controllerCont = document.querySelector('#controller'); - var progressCont = document.querySelector('#progress-contaniner'); - var progressContW = progressCont.offsetWidth; - var cachePts = progressCont.querySelector('#cachePts'); - var progressPts = progressCont.querySelector('#progressPts'); - var progressVoice = document.querySelector('#progressVoice'); - var playBar = document.querySelector('#playBar'); - var playBtn = playBar.getElementsByTagName('a')[0]; - var showLabel = document.querySelector('#showLabel'); - var ptsLabel = document.querySelector('#ptsLabel'); - var coverToast = document.querySelector('#coverLayer'); - var coverBtn = document.querySelector('#coverLayerBtn'); - var muteBtn = document.querySelector('#muteBtn'); // let debugYUVBtn = document.querySelector('#debugYUVBtn'); - // let debugYUVATag = document.querySelector('#debugYUVUrl'); - - var fullScreenBtn = document.querySelector('#fullScreenBtn'); - var mediaInfo = null; - playBtn.disabled = true; - playBtn.textContent = '>'; - var muteState = false; // controllerCont.style.left = playerContainer.clientLeft; - // controllerCont.style.bottom = playerContainer.clientBottom; - // alert(playerContainer.clientLeft); - - var playAction = function playAction() { - console.log("is playing:", playerObj.isPlaying()); - - if (playerObj.isPlaying()) { - console.log("bar pause============>"); // playBar.textContent = '>'; - - playBar.setAttribute('class', 'playBtn'); - playerObj.pause(); - } else { - // playBar.textContent = '||'; - playBar.setAttribute('class', 'pauseBtn'); - playerObj.play(); - } - }; - - playerCont.onmouseover = function () { - controllerCont.hidden = false; - }; - - playerCont.onmouseout = function () { - controllerCont.hidden = true; - }; - - playerDom.onmouseup = function () { - playAction(); - }; - - playBtn.onclick = function () { - playAction(); - }; - - muteBtn.onclick = function () { - console.log(playerObj.getVolume()); - - if (muteState === true) { - playerObj.setVoice(1.0); - progressVoice.value = 100; - } else { - playerObj.setVoice(0.0); - progressVoice.value = 0; - } - - muteState = !muteState; - }; - - fullScreenBtn.onclick = function () { - playerObj.fullScreen(); - }; - - playerObj.onRender = function (width, height, imageBufferY, imageBufferB, imageBufferR) { - // screenView.render(width, height, imageBufferY, imageBufferB, imageBufferR); - console.log("on render"); - }; - - playerObj.onPlayTime = function (videoPTS) { - if (mediaInfo.videoType == "vod") { - // progressPts.value = videoPTS; - var precent = videoPTS / progressCont.max; - var progWidth = precent * progressContW; // console.log(precent, precent * progressCont.offsetWidth); - - progressPts.style.width = progWidth + 'px'; - ptsLabel.textContent = durationText(videoPTS) + '/' + durationText(progressCont.max); - } else { - // ptsLabel.textContent = durationText(videoPTS) + '/LIVE'; - ptsLabel.textContent = '/RAW'; - } - }; - - playerObj.onReadyShowDone = function () { - console.log("onReadyShowDone"); - showLabel.textContent = "Done"; - playBar.setAttribute('class', 'pauseBtn'); - }; - - playerObj.onLoadFinish = function () { - playerObj.setVoice(1.0); - mediaInfo = playerObj.mediaInfo(); - console.log("mediaInfo===========>", mediaInfo); - showLabel.textContent = "loading cover"; - /* - meta: - durationMs: 144400 - fps: 25 - sampleRate: 44100 - size: { - width: 864, - height: 480 - }, - audioNone : false - videoType: "vod" - */ - - playBar.disabled = false; - - if (mediaInfo.meta.audioNone) { - progressVoice.value = 0; - progressVoice.style.display = 'none'; - } - - if (mediaInfo.videoType == "vod") { - progressPts.max = mediaInfo.meta.durationMs / 1000; - ptsLabel.textContent = '0:0:0/' + durationText(progressPts.max); - } else { - cachePts.hidden = true; - progressCont.hidden = true; - ptsLabel.textContent = 'RAW'; - - if (mediaInfo.meta.audioNone === true) { - // playBar.textContent = '||'; - playerObj.play(); - } else { - coverToast.removeAttribute('hidden'); - - coverBtn.onclick = function () { - // playBar.textContent = '||'; - playerObj.play(); - coverToast.setAttribute('hidden', 'hidden'); - }; - } - } // showLabel.textContent = SHOW_DONE; - - - var fetchFinished = false; - var stopNaluInterval = false; - - var naluGetFunc = function naluGetFunc() { - setTimeout(function () { - workerParse.postMessage({ - cmd: "get-nalu", - data: null, - msg: "get-nalu" - }); - - if (stopNaluInterval === true) { - return; - } // naluGetFunc(); - - }, 1000); - }; - - workerFetch.onmessage = function (event) { - // console.log("play -> workerFetch recv:", event, playerObj); - var body = event.data; - var cmd = null; - - if (body.cmd === undefined || body.cmd === null) { - cmd = ''; - } else { - cmd = body.cmd; - } // console.log("play -> workerFetch recv cmd:", cmd); - - - switch (cmd) { - case 'fetch-chunk': - // console.log("play -> workerFetch append chunk"); - var chunk = body.data; - workerParse.postMessage({ - cmd: "append-chunk", - data: chunk, - msg: "append-chunk" - }); - break; - - case 'fetch-fin': - fetchFinished = true; - break; - - default: - break; - } - }; - - workerParse.onmessage = function (event) { - // return-nalu - // console.log("play -> workerParse recv:", event, playerObj); - var body = event.data; - var cmd = null; - - if (body.cmd === undefined || body.cmd === null) { - cmd = ''; - } else { - cmd = body.cmd; - } // console.log("play -> workerParse recv cmd:", cmd); - - - switch (cmd) { - case 'return-nalu': - var nalBuf = body.data; - - if (nalBuf === false || nalBuf === null || nalBuf === undefined) { - if (fetchFinished === true) { - stopNaluInterval = true; - } - } else { - // console.warn("play -> workerParse nalu"); - playerObj.append265NaluFrame(nalBuf); - workerParse.postMessage({ - cmd: "get-nalu", - data: null, - msg: "get-nalu" - }); - } - - break; - - default: - break; - } - }; - - workerFetch.postMessage({ - cmd: "start", - data: url265, - msg: "start" - }); - naluGetFunc(); - }; // onloadfinish - - playerObj["do"](); return playerObj; }; diff --git a/example/index.html b/example/index.html index 7e943206..1225d8be 100644 --- a/example/index.html +++ b/example/index.html @@ -124,6 +124,9 @@

h265web.js 播放器 Demo

// var url = "http://127.0.0.1/live/test.live.ts"; // var url = "http://127.0.0.1/live/test/hls.m3u8"; + /******** raw hevc http(vod) *****/ + // var url = "http://127.0.0.1/test.h265"; + var config = { player: "glplayer", width: 960, @@ -131,29 +134,11 @@

h265web.js 播放器 Demo

token : token, extInfo : { coreProbePart : 0.4, - probeSize : 8192 + probeSize : 8192, + // rawFps : 30 // if raw hevc stream } }; makeH265webjs(url, config); - - /* - * Play raw 265 demo - */ - /* - var type = "raw265"; - var url265raw = "/res/spreedmovie.hevc"; - var config = { - type: type, - player: "glplayer", - width: 960, - height: 540, - token : token, - extInfo : { - rawFps : 30 - } - }; - var h265Object = makeH265webjsRaw(url265raw, config); - */ diff --git a/example/play.js b/example/play.js index acddbc97..f5cbe5d6 100644 --- a/example/play.js +++ b/example/play.js @@ -311,267 +311,6 @@ global.makeH265webjs = (videoURL, config) => { return playerObj; }; -/*************************************************** - * - * - * - * 2. RAW HEVC DEMO - * HEVC/H.265, Demo for VOD, 点播文件播放demo - * - * - * - ***************************************************/ -var workerFetch = new Worker('./dist/worker-fetch-dist.js'); -var workerParse = new Worker('./dist/worker-parse-dist.js'); -console.log("workerFetch:", workerFetch); -console.log("workerParse:", workerParse); -/* - * 创建265流播放器 - */ -global.makeH265webjsRaw = (url265, config) => { - let playerId = config.player; - let playerObj = H265webjsModule.createPlayer(null, config); - - let playerDom = document.querySelector('#' + playerId); - let playerCont = document.querySelector('#player-container'); - let controllerCont = document.querySelector('#controller'); - let progressCont = document.querySelector('#progress-contaniner'); - let progressContW = progressCont.offsetWidth; - let cachePts = progressCont.querySelector('#cachePts'); - let progressPts = progressCont.querySelector('#progressPts'); - let progressVoice = document.querySelector('#progressVoice'); - let playBar = document.querySelector('#playBar'); - let playBtn = playBar.getElementsByTagName('a')[0]; - let showLabel = document.querySelector('#showLabel'); - let ptsLabel = document.querySelector('#ptsLabel'); - let coverToast = document.querySelector('#coverLayer'); - let coverBtn = document.querySelector('#coverLayerBtn'); - let muteBtn = document.querySelector('#muteBtn'); - // let debugYUVBtn = document.querySelector('#debugYUVBtn'); - // let debugYUVATag = document.querySelector('#debugYUVUrl'); - let fullScreenBtn = document.querySelector('#fullScreenBtn'); - - let mediaInfo = null; - - playBtn.disabled = true; - playBtn.textContent = '>'; - - let muteState = false; - - // controllerCont.style.left = playerContainer.clientLeft; - // controllerCont.style.bottom = playerContainer.clientBottom; - // alert(playerContainer.clientLeft); - - let playAction = () => { - console.log("is playing:", playerObj.isPlaying()); - if (playerObj.isPlaying()) { - console.log("bar pause============>"); - // playBar.textContent = '>'; - playBar.setAttribute('class', 'playBtn'); - playerObj.pause(); - } else { - // playBar.textContent = '||'; - playBar.setAttribute('class', 'pauseBtn'); - playerObj.play(); - } - }; - - playerCont.onmouseover = function() { - controllerCont.hidden = false; - }; - - playerCont.onmouseout = function() { - controllerCont.hidden = true; - }; - - playerDom.onmouseup = function() { - playAction(); - }; - - playBtn.onclick = () => { - playAction(); - }; - - muteBtn.onclick = () => { - console.log(playerObj.getVolume()); - if (muteState === true) { - playerObj.setVoice(1.0); - progressVoice.value = 100; - } else { - playerObj.setVoice(0.0); - progressVoice.value = 0; - } - muteState = !muteState; - }; - - fullScreenBtn.onclick = () => { - playerObj.fullScreen(); - }; - - - playerObj.onRender = (width, height, imageBufferY, imageBufferB, imageBufferR) => { - // screenView.render(width, height, imageBufferY, imageBufferB, imageBufferR); - console.log("on render"); - }; - - playerObj.onPlayTime = (videoPTS) => { - if (mediaInfo.videoType == "vod") { - // progressPts.value = videoPTS; - let precent = videoPTS / progressCont.max; - let progWidth = precent * progressContW; - // console.log(precent, precent * progressCont.offsetWidth); - progressPts.style.width = progWidth + 'px'; - - ptsLabel.textContent = durationText(videoPTS) + '/' + durationText(progressCont.max); - } else { - // ptsLabel.textContent = durationText(videoPTS) + '/LIVE'; - ptsLabel.textContent = '/RAW'; - } - }; - - playerObj.onReadyShowDone = () => { - console.log("onReadyShowDone"); - showLabel.textContent = "Done"; - playBar.setAttribute('class', 'pauseBtn'); - }; - - playerObj.onLoadFinish = () => { - playerObj.setVoice(1.0); - mediaInfo = playerObj.mediaInfo(); - console.log("mediaInfo===========>", mediaInfo); - showLabel.textContent = "loading cover"; - /* - meta: - durationMs: 144400 - fps: 25 - sampleRate: 44100 - size: { - width: 864, - height: 480 - }, - audioNone : false - videoType: "vod" - */ - playBar.disabled = false; - - if (mediaInfo.meta.audioNone) { - progressVoice.value = 0; - progressVoice.style.display = 'none'; - } - - if (mediaInfo.videoType == "vod") { - progressPts.max = mediaInfo.meta.durationMs / 1000; - ptsLabel.textContent = '0:0:0/' + durationText(progressPts.max); - } else { - cachePts.hidden = true; - progressCont.hidden = true; - ptsLabel.textContent = 'RAW'; - - if (mediaInfo.meta.audioNone === true) { - // playBar.textContent = '||'; - playerObj.play(); - } else { - coverToast.removeAttribute('hidden'); - coverBtn.onclick = () => { - // playBar.textContent = '||'; - playerObj.play(); - coverToast.setAttribute('hidden', 'hidden'); - } - } - } - // showLabel.textContent = SHOW_DONE; - - let fetchFinished = false; - let stopNaluInterval = false; - let naluGetFunc = () => { - setTimeout(() => { - workerParse.postMessage({ - cmd : "get-nalu", - data : null, - msg : "get-nalu" - }); - if (stopNaluInterval === true) { - return; - } - // naluGetFunc(); - }, 1000); - }; - - workerFetch.onmessage = event => { - // console.log("play -> workerFetch recv:", event, playerObj); - let body = event.data; - let cmd = null; - if (body.cmd === undefined || body.cmd === null) { - cmd = ''; - } else { - cmd = body.cmd; - } - - // console.log("play -> workerFetch recv cmd:", cmd); - - switch (cmd) { - case 'fetch-chunk': - // console.log("play -> workerFetch append chunk"); - let chunk = body.data; - workerParse.postMessage({ - cmd : "append-chunk", - data : chunk, - msg : "append-chunk" - }); - break; - case 'fetch-fin': - fetchFinished = true; - break; - default: - break; - } - }; - - workerParse.onmessage = event => { - // return-nalu - // console.log("play -> workerParse recv:", event, playerObj); - let body = event.data; - let cmd = null; - if (body.cmd === undefined || body.cmd === null) { - cmd = ''; - } else { - cmd = body.cmd; - } - - // console.log("play -> workerParse recv cmd:", cmd); - - switch (cmd) { - case 'return-nalu': - let nalBuf = body.data; - if (nalBuf === false || nalBuf === null || nalBuf === undefined) - { - if (fetchFinished === true) { - stopNaluInterval = true; - } - } else { - // console.warn("play -> workerParse nalu"); - playerObj.append265NaluFrame(nalBuf); - workerParse.postMessage({ - cmd : "get-nalu", - data : null, - msg : "get-nalu" - }); - } - break; - default: - break; - } - }; - - workerFetch.postMessage({cmd: "start", data: url265, msg: "start"}); - naluGetFunc(); - }; // onloadfinish - - playerObj.do(); - return playerObj; -}; - - /*************************************************** * *