Jesse RJ
Jesse RJ

Reputation: 239

setting the playback rate of html5 video in html

When watching a video, its possible to enter developer mode in the browser and enter the following command in the console to change the playback speed of a video

document.getElementsByTagName('video')[0].playbackRate = 0.9

When I try however to code this in html I am unable to access the video object.

var obj = document.getElementsByTagName('video');
console.log(obj);

returns an object of length 0

also trying

var player1 = document.getElementById("video");
console.log(player1);
player1.playbackRate = 2;

returns null

A demo of the not working code so far is here: https://jsbin.com/peludojisi/1/edit?html,js,console,output

Can someone please help me figure out how to set the playbackRate from html

many thanks in advance

Jesse

Upvotes: 0

Views: 6158

Answers (1)

junvar
junvar

Reputation: 11574

document.querySelector does not work across iframes. Since the video in your example is within an iframe, your query returns null.

The error message in you snippet tells you almost as much:

"TypeError: Cannot set property 'defaultPlaybackRate' of null at :16:59

Line 16 of your script:

  document.querySelector('video').defaultPlaybackRate = 2.0;

Upvotes: 2

Related Questions