HTML5 Video Playback Rate

荒凉一梦 提交于 2021-01-28 19:58:35

问题


I'm trying to use a drop down window to be able to change the rate of which a video is playing at.

I've added the options on markup here:

        <select id="playBackRateDrop">
            <option>0.5</option>
            <option selected= "selected">1</option>
            <option>1.5</option>
            <option>2</option>
        </select>

Added a variable to getElementById here var playRate= document.getElementById("playBackRateDrop");

Added a actionListener to the dropdown window playRate.addEventListener("select", setPlaySpeed);

And created a function here

function setPlaySpeed() {
        var rate= playRate.options[selectedIndex].value;
        video.playbackRate= rate;
    }

For some reason, the selecting an option from the dropdown doesn't change anything, the video plays as normal.


回答1:


You should listen for the event change not select:

playRate.addEventListener("change", setPlaySpeed);

Furthermore, you should use playRate.value to get the value of the select. Then use parseFloat to get the float value of the returned string. This results in the following function:

function setPlaySpeed() {
    var rate= playRate.value;
    video.playbackRate= parseFloat(rate);
}


来源:https://stackoverflow.com/questions/40617585/html5-video-playback-rate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!