html5 video無法快進(jìn)的解決辦法:1、創(chuàng)建鍵盤事件“document.onkeyup = function (event){…}”;2、打印出request中傳遞的所有參數(shù)名稱;3、根據(jù)Range屬性值來獲取到需要將視頻定位的位置;4、在catch中將異常屏蔽掉即可。
本教程操作環(huán)境:Windows10系統(tǒng)、HTML5版、Dell G3電腦。
html5 video無法快進(jìn)怎么辦?
<video> 標(biāo)簽快進(jìn)不生效的解決:
在H5項目中,使用<video>標(biāo)簽來播放視頻,跳不過視頻的快進(jìn)播放,按照原生提供的方法,來進(jìn)行如下監(jiān)聽設(shè)置:
var vol = 0.1; //1代表100%音量,每次增減0.1 var time = 2; //單位秒,每次增減10秒 function listenKeyboard() { var videoElement = document.getElementById("video"); document.onkeyup = function (event) {//鍵盤事件 var e = event || window.event || arguments.callee.caller.arguments[0]; //鼠標(biāo)上下鍵控制視頻音量 if (e && e.keyCode === 38) { console.log("音量加1"); // 按 向上鍵 videoElement.volume !== 1 ? videoElement.volume += vol : 1; return false; } else if (e && e.keyCode === 40) { console.log("音量減1"); // 按 向下鍵 videoElement.volume !== 0 ? videoElement.volume -= vol : 1; return false; } else if (e && e.keyCode === 37) { console.log("倒退1秒"); // 按 向左鍵 videoElement.currentTime !== 0 ? videoElement.currentTime = videoElement.currentTime -= time : 1; return false; } else if (e && e.keyCode === 39) { console.log("前進(jìn)2秒,當(dāng)前時間是:"+videoElement.currentTime+",視頻長度是:"+videoElement.duration); // 按 向右鍵 var currPlayTime = videoElement.currentTime ; if (currPlayTime !== videoElement.duration){ var afterSetTime = currPlayTime + time ; console.log('afterSetTime should be :'+afterSetTime) ; videoElement.currentTime = afterSetTime ; console.log('afterSetTime is :'+videoElement.currentTime) ; }else { videoElement.currentTime = videoElement.currentTime + 1; } console.log("快進(jìn)后的時間是:"+videoElement.currentTime); return false; } else if (e && e.keyCode === 32) { console.log("暫停"); // 按空格鍵 判斷當(dāng)前是否暫停 videoElement.paused === true ? videoElement.play() : videoElement.pause(); return false; } } }
登錄后復(fù)制
每次快進(jìn)時,視頻會跳動到開始,重新進(jìn)行播放。
后在想,視頻每次播放,讀取的文件流肯定不同,需要從文件對應(yīng)的位置進(jìn)行截取,類似于翻頁一樣,需要傳遞一個起始邊界值,于是打印出request中傳遞的所有參數(shù)名稱,但除了業(yè)務(wù)參數(shù)外,并沒有其他