Vimeo API:简单的播放按钮

发布于 2024-11-05 10:33:32 字数 118 浏览 2 评论 0原文

Vimeo API 文档让我手足无措,完全不知道该怎么做。

我想创建一个简单的按钮来播放我的视频。有人可以提供一个简单的例子吗?它可能会帮助我更好地理解这个 API 是如何工作的。

谢谢你!

The Vimeo API documentation has me running in circles and I can't quite figure out what to do.

I want to create a simple button that plays my video. Could someone provide a bare-bones example of this? It might help me better understand how this API works.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

临走之时 2024-11-12 10:33:32

它甚至可以更简单:这对我有用(页面上只有一个视频)

<iframe id="vid_id" 
        src="http://player.vimeo.com/video/123456789" 
        height="288" width="512" allowfullscreen>
</iframe>
<br>
<button onclick="play_video()">Button text</button>

<script>
function play_video() {
  var player = document.getElementById("vid_id");
  var data = { method: "play" };
  player.contentWindow.postMessage(JSON.stringify(data), "*");
}
</script>

并且在调用 api=1player_id 时似乎不需要 api=1player_id代码>player.vimeo.com。
我在 IE8、IE11、Fx、Chrome、Safari、Opera 上进行了测试。

(稍后编辑):Android 似乎是另一个故事;我一直无法找到 Android 下的编程控制的任何工作示例。我已将此事通知 Vimeo。

It can be even simpler: this works for me (only one video on the page)

<iframe id="vid_id" 
        src="http://player.vimeo.com/video/123456789" 
        height="288" width="512" allowfullscreen>
</iframe>
<br>
<button onclick="play_video()">Button text</button>

<script>
function play_video() {
  var player = document.getElementById("vid_id");
  var data = { method: "play" };
  player.contentWindow.postMessage(JSON.stringify(data), "*");
}
</script>

And it doesn't seem to need api=1 or player_id in the call to player.vimeo.com.
I tested it on IE8, IE11, Fx, Chrome, Safari, Opera.

(edit later): Android seems to be another story; I have been unable to find any working example of programmatic control under Android. I have notified Vimeo of this.

你怎么这么可爱啊 2024-11-12 10:33:32

我认为 Vimeo API 文档也非常令人困惑,这就是我这样做的原因:
http://labs.funkhausdesign.com/examples/vimeo/froogaloop2-api -basics.html

它尽可能简单。

I think the Vimeo API docs are super confusing as well, that's why I made this:
http://labs.funkhausdesign.com/examples/vimeo/froogaloop2-api-basics.html

It's as bare bones as possible.

假装不在乎 2024-11-12 10:33:32

我想添加一个像这样的播放/暂停按钮,而不使用 jquery 或 froogaloop。我不知道为什么,但是,我讨厌在不必要的时候包含一个图书馆。尤其是对于像这样简单的事情。

这是我想到的(我只是将其发布给其他正在搜索的人):

<!DOCTYPE HTML>
<html>
<head>
    <title>Vimeo Test</title>
    <script language="JavaScript">
    var iFram, url;
    function startitup(){
        iFram = document.getElementById('theClip');
        url = iFram.src.split('?')[0];
    }
    function postIt(action, value) {
        var data = { method: action };
        if (value) {
            data.value = value;
        }
        if(url !== undefined){
            iFram.contentWindow.postMessage(JSON.stringify(data), url);
        }
    }
</script>
</head>
<body onload="startitup();">
<iframe id="theClip" src="http://player.vimeo.com/video/27855315?api=1" width="400"     height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen>    </iframe>
<p><button onclick="postIt('play');">Play</button> <button     onclick="postIt('pause');">Pause</button></p>
</body>
</html>

I wanted to add a play/pause button like this without using jquery or froogaloop. I don't know why but, I hate including a library when I don't have to. Especially for simple things like this.

Here's what I came up with (I'm just posting this for other people who are searching) :

<!DOCTYPE HTML>
<html>
<head>
    <title>Vimeo Test</title>
    <script language="JavaScript">
    var iFram, url;
    function startitup(){
        iFram = document.getElementById('theClip');
        url = iFram.src.split('?')[0];
    }
    function postIt(action, value) {
        var data = { method: action };
        if (value) {
            data.value = value;
        }
        if(url !== undefined){
            iFram.contentWindow.postMessage(JSON.stringify(data), url);
        }
    }
</script>
</head>
<body onload="startitup();">
<iframe id="theClip" src="http://player.vimeo.com/video/27855315?api=1" width="400"     height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen>    </iframe>
<p><button onclick="postIt('play');">Play</button> <button     onclick="postIt('pause');">Pause</button></p>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文