3x3-demo.html 12.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>Jessibuca Pro 3x3 demo</title>
    <script src="./vconsole.js"></script>
    <script src="./jessibuca-pro-demo.js"></script>
    <link rel="stylesheet" href="./demo.css">
    <style>
        .container-shell:before {
            content: "jessibuca Pro 3x3 demo player";
        }
    </style>
</head>
<body class="page">
<div class="root">

    <div class="container-shell">
        <div class="container-multi">
            <div class="container" id="container1"></div>
            <div class="container" id="container2"></div>
            <div class="container" id="container3"></div>
        </div>
        <div class="container-multi">
            <div class="container" id="container4"></div>
            <div class="container" id="container5"></div>
            <div class="container" id="container6"></div>
        </div>
        <div class="container-multi">
            <div class="container" id="container7"></div>
            <div class="container" id="container8"></div>
            <div class="container" id="container9"></div>
        </div>
        <div class="input">
            <div>
                当前浏览器:
                <span id="mseSupport264" style="color: green;display: none">支持MSE H264解码;</span>
                <span id="mseSupport" style="color: green;display: none">支持MSE H265解码;</span>
                <span id="mseNotSupport264" style="color: red;display: none">不支持MSE H264解码;</span>
                <span id="mseNotSupport"
                      style="color: red;display: none">不支持MSE H265解码,会自动切换成wasm解码;</span>
            </div>
        </div>
        <div class="input">
            <div>
                当前浏览器:
                <span id="wcsSupport264" style="color: green;display: none">支持Webcodecs H264解码;</span>
                <span id="wcsSupport" style="color: green;display: none">支持Webcodecs H265解码(不一定准确);</span>
                <span id="wcsNotSupport264"
                      style="color: red;display: none">不支持Webcodecs H264解码(https/localhost);</span>
                <span id="wcsNotSupport" style="color: red;display: none">不支持Webcodecs H265解码(https/localhost),会自动切换成wasm解码</span>
            </div>
        </div>
        <div class="input">
            <div>
                当前浏览器:
                <span id="simdSupport" style="color: green;display: none">支持WASM SIMD解码</span>
                <span id="simdNotSupport"
                      style="color: red;display: none">不支持WASM SIMD解码,会自动切换成wasm解码</span>
            </div>
        </div>
        <div class="input">
            <div>
                <div>js为单线程运行时, 无法通过多线程提升并发性能.</div>
                <div>将音视频解码在worker中进行, 能有效利用多核处理器提升多画面播放的流畅度.</div>
                <div>
                    chrome限制同源http请求最多6个并发, 因此超过6个并发请求我们采用websocket-flv来播放
                </div>
                <div>请准备M7S服务端来测试. worker js不能跨域调用,</div>
            </div>
        </div>
        <div class="input">
            <div><input
                type="checkbox"
                checked
                id="useMSE"
            /><span>MediaSource</span>
                <input
                    type="checkbox"
                    id="useWCS"
                /><span>Webcodec</span>
                <input
                    type="checkbox"
                    id="useSIMD"
                /><span>SIMD</span>
            </div>
        </div>
        <div class="input">
            <div>
                <input
                    checked
                    type="checkbox"
                    id="isFlv"
                /><span>是否flv格式</span>
                <span>缓存时长:</span>
                <input placeholder="单位:秒" type="text" id="videoBuffer" style="width: 50px" value="0.2">
                <span>缓存延迟(延迟超过会触发丢帧):</span>
                <input placeholder="单位:秒" type="text" id="videoBufferDelay" style="width: 50px" value="2">
                <button id="replay">重播</button>
            </div>
        </div>
        <div class="input">
            <div>
                <input
                    checked
                    onclick="replay()"
                    type="checkbox"
                    id="demuxUseWorker"
                /><span>硬解码(MediaSource,Webcodec)worker解封装</span>
            </div>
        </div>
        <div class="input">
            <div>
                <input
                    onclick="toggleDebugLevel()"
                    type="checkbox"
                    id="isDebug"
                /><span>开启日志</span>

            </div>
        </div>

        <div class="input">
            <div>输入URL:</div>
            <input
                autocomplete="on"
                id="playUrl1"
                value=""
            />
        </div>
        <div class="input">
            <div>输入URL:</div>
            <input
                autocomplete="on"
                id="playUrl2"
                value=""
            />
        </div>
        <div class="input">
            <div>输入URL:</div>
            <input
                autocomplete="on"
                id="playUrl3"
                value=""
            />
        </div>
        <div class="input">
            <div>输入URL:</div>
            <input
                autocomplete="on"
                id="playUrl4"
                value=""
            />
        </div>
        <div class="input">
            <div>输入URL:</div>
            <input
                autocomplete="on"
                id="playUrl5"
                value=""
            />
        </div>
        <div class="input">
            <div>输入URL:</div>
            <input
                autocomplete="on"
                id="playUrl6"
                value=""
            />
        </div>
        <div class="input">
            <div>输入URL:</div>
            <input
                autocomplete="on"
                id="playUrl7"
                value=""
            />
        </div>
        <div class="input">
            <div>输入URL:</div>
            <input
                autocomplete="on"
                id="playUrl8"
                value=""
            />
        </div>
        <div class="input">
            <div>输入URL:</div>
            <input
                autocomplete="on"
                id="playUrl9"
                value=""
            />
        </div>
        <div class="input">
            <button id="play">播放</button>
            <button id="pause" style="display: none">停止</button>
        </div>
        <div class="input" style="line-height: 30px">
            <button id="destroy">销毁</button>
        </div>
    </div>
</div>

<script src="./demo.js"></script>

<script>
    var $player = document.getElementById('play');
    var $pause = document.getElementById('pause');
    var $destroy = document.getElementById('destroy');
    var $useMSE = document.getElementById('useMSE');
    var $useSIMD = document.getElementById('useSIMD');
    var $useWCS = document.getElementById('useWCS');
    var $videoBuffer = document.getElementById('videoBuffer');
    var $videoBufferDelay = document.getElementById('videoBufferDelay');
    var $replay = document.getElementById('replay');
    var $demuxUseWorker = document.getElementById('demuxUseWorker');
    var $isDebug = document.getElementById('isDebug');
    var $isFlv = document.getElementById('isFlv');

    var showOperateBtns = true; // 是否显示按钮
    var forceNoOffscreen = true; //
    var playList = [];
    let size = 9

    function _create(id) {
        var $container = document.getElementById('container' + id);

        var jessibuca = new JessibucaPro({
            container: $container,
            decoder: './decoder-pro.js',
            videoBuffer: 0.2, // 缓存时长
            isResize: false,
            text: "",
            loadingText: "加载中",
            debug: true,
            debugLevel: $isDebug.checked === true ? "debug" : '',
            isMulti: true,
            useMSE: $useMSE.checked === true,
            useSIMD: $useSIMD.checked === true,
            useWCS: $useWCS.checked === true,
            hasAudio: false,
            useVideoRender: true,
            controlAutoHide: true,
            showBandwidth: showOperateBtns, // 显示网速
            showPerformance: showOperateBtns,
            isFlv: $isFlv.checked === true,
            operateBtns: {
                fullscreen: showOperateBtns,
                screenshot: showOperateBtns,
                play: showOperateBtns,
                audio: showOperateBtns,
            },
            watermarkConfig: {
                text: {
                    content: 'jessibuca-pro'
                },
                right: 10,
                top: 10
            },
            demuxUseWorker: $demuxUseWorker.checked === true,
        },);

        jessibuca.on("fullscreen", function (flag) {
            console.log('is fullscreen', id, flag)
        })
        playList.push(jessibuca);
    }

    function create() {
        for (let i = 0; i < size; i++) {
            _create(i + 1);
            $player.style.display = 'inline-block';
            $pause.style.display = 'none';
            $destroy.style.display = 'none';
        }
    }

    create();

    function play() {
        for (let i = 0; i < size; i++) {
            var id = i + 1;
            var $playHref = document.getElementById('playUrl' + id);
            let player = playList[i];
            if ($playHref.value) {
                setTimeout((url) => {
                    console.log(url);
                    player && player.play(url).then(() => {

                    }).catch((e) => {
                        console.error(e);
                    });
                }, 0, $playHref.value)
            }
        }

        $player.style.display = 'none';
        $pause.style.display = 'inline-block';
        $destroy.style.display = 'inline-block';
    }

    function destroyAndCreate() {
        return new Promise((resolve, reject) => {
            const destroyList = [];
            for (let i = 0; i < size; i++) {
                let player = playList[i];
                if (player) {
                    destroyList.push(player.destroy());
                }
            }
            Promise.all(destroyList).then(() => {
                playList = [];
                setTimeout(() => {
                    create()
                    resolve();
                }, 100)
            }).catch((e) => {
                console.error(e);
            })
        })

    }

    function replay() {
        destroyAndCreate().then(() => {
            play();
        });
    }


    function pause() {
        $player.style.display = 'inline-block';
        $pause.style.display = 'none';
        for (let i = 0; i < size; i++) {
            let player = playList[i];
            player && player.pause()
        }
    }

    $player.addEventListener('click', function () {
        play();
    }, false)


    $pause.addEventListener('click', function () {
        pause();
    })

    $destroy.addEventListener('click', function () {
        destroyAndCreate().then(() => {

        });
    })

    $replay.addEventListener('click', function () {
        replay();
    })

    $useMSE.addEventListener('click', function () {
        const checked = $useMSE.checked;
        if (checked) {
            $useSIMD.checked = false
            $useWCS.checked = false
        }
        replay();
    })

    $useSIMD.addEventListener('click', function () {
        const checked = $useSIMD.checked;
        if (checked) {
            $useMSE.checked = false
            $useWCS.checked = false
        }
        replay();
    })

    $useWCS.addEventListener('click', function () {
        const checked = $useWCS.checked;
        if (checked) {
            $useMSE.checked = false
            $useSIMD.checked = false
        }
        replay();
    })


    function toggleDebugLevel() {

        for (let i = 0; i < size; i++) {
            let player = playList[i];
            if(player){
                const isDebug = $isDebug.checked === true;
                player.updateDebugLevel(isDebug ? 'debug' : 'warn')
            }
        }

    }
</script>

</body>
</html>