Reputation: 105
I embedded a YouTube video in a web site and want to change the speed of this video. I know that it is possible to change speed in HTML5 videos (cf How to change the playing speed of videos in HTML5?). The problem is that YouTube videos are embedded as an iframe.
I found this code jsfiddle.net/jpreynat/e11oy0eu/ but it only works on desktops and not with mobile devices.
Is there a possibility to change the YouTube video speed on every device?
Upvotes: 0
Views: 4686
Reputation: 7674
Try using postMessage on iframe to pass setPlaybackRate command with rate in argument
var playbackRate = 2;
var data = {event: 'command', func: 'setPlaybackRate', args: [playbackRate, true]};
var message = JSON.stringify(data);
$('#iframe1')[0].contentWindow.postMessage(message, '*');
Upvotes: 5