如何更改嵌入式 Youtube 视频的速度 [英] How to change speed on embedded Youtube video

查看:36
本文介绍了如何更改嵌入式 Youtube 视频的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站中嵌入了一个 youtube 视频,并想更改该视频的速度.我知道可以改变 HTML5 视频的速度(参见 如何更改 HTML5 中视频的播放速度?).问题是 Youtube 视频是作为 iframe 嵌入的.

I embedded a youtube video in a website 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.

我发现此代码为 jsfiddle.net/jpreynat/e11oy0eu/,但它仅适用于台式机,不适用于移动设备.

I found this code jsfiddle.net/jpreynat/e11oy0eu/ but it only works on desktops and not with mobile devices.

是否有可能在每台设备上更改 Youtube 视频速度?

Is there a possibility to change the Youtube video speed on every device?

推荐答案

尝试在 iframe 上使用 postMessage 以参数中的速率传递 setPlaybackRate 命令

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, '*');

这篇关于如何更改嵌入式 Youtube 视频的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆