bsaid97 bsaid97 - 1 year ago 147
Javascript Question

HTML5 Video Playback Rate

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 selected= "selected">1</option>

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.

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download