【问题标题】:How do I change playbackRate in html5 video contained in a you-tube iframe?如何更改 youtube iframe 中包含的 html5 视频中的播放率?
【发布时间】:2015-10-10 01:16:11
【问题描述】:

有一个 chrome 扩展程序允许为 youtube iframe 中包含的 html5 视频设置和更改播放率。

我想在 Firefox(或者更好的是,独立于浏览器)上完成同样的事情。

我想知道我是否必须通过附加组件来执行此操作(因为我的 html 不在 YouTube 上,但我的视频在,所以能够跨站点进行消息传递),或者是否有更简单的方法(甚至可以跨浏览器工作)。

关于此事的任何想法都会很有用。

根据 Rachel Gallen(在 cmets 中)的出色建议,我尝试了以下一些方法:

$(function (){
  // a convenient way to get at things once the page renders
  $("button#stop-me").click(function() {
    var mytags = document.getElementsByTagName("video");
  });
});

$(function (){
  // a convenient way to get at things once the page renders
  $("button#stop-me").click(function() {
    var myframe = document.getElementsByTagName("iframe");
    for(p in myframe)
    {
      var mytags = myframe.document.getElementsByTagName("video");
    }
  });
});

$(function (){

  document.addEventListener('DOMNodeInserted', function(event) {
    var node = event.target || null;
    if (node && node.nodeName === 'VIDEO') {
      nodeList.push(node);
    }
  });

  $("button#stop-me").click(function() {
    alert(nodeList.length);
  });
});

第一个返回一个空的“mytags”。

第二个返回 iframe 列表,但 myframe.document 调用出错(如预期的那样)。

第三个 on 永远不会碰到 nodeList.push(node) 行并显示计数为 0(如预期)

【问题讨论】:

    标签: html video cross-domain


    【解决方案1】:

    我还没有测试过,但它应该可以工作

    document.getElementsByTagName("video")[0].playbackRate = 1.2 应该将其加速到 1.2 倍的速度

    (同样 0.7 会减慢速度等)

    【讨论】:

    • 试过了。它不起作用(我认为是因为“视频”标签在 iframe 内,浏览器认为这些标签是禁止的,因为它们是跨域的)。
    【解决方案2】:

    如果可能,最好使用 Youtube 的 API。你不知道 Youtube 会显示什么,它可能(例如)甚至不是 HTML5 视频,它可能是其他东西,比如 flash。因此,虽然有可能破解它,但这不是最好的方法。

    【讨论】:

    • 我没有在 Youtube 的 API 中看到此功能。我错过了吗?
    猜你喜欢
    • 2011-02-15
    • 1970-01-01
    • 2011-03-02
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 2015-05-03
    相关资源
    最近更新 更多