简体   繁体   English

Flowplayer Javascript 事件

[英]Flowplayer Javascript events

I am trying to do something when the video starts playing.当视频开始播放时,我正在尝试做一些事情。 I've found onStart in the documentation, BUT wherever I look, the player is initialized differently than I have it setup.我在文档中找到了onStart ,但是无论我在哪里看,播放器的初始化都与我设置的不同。

This is my code:这是我的代码:

$("#my-player").flowplayer({
    adaptiveRatio: true
});

And this is what I keep finding:这就是我不断发现的:

flowplayer("player", "flowplayer-3.2.18.swf", {
    clip: {
        onStart: function(clip) {
            // some code
        }
    }
});

I've tried:我试过了:

$("#my-player").flowplayer({
    adaptiveRatio: true,
    onStart: function() { alert('movie has started'); }
});

OR或者

$("#my-player").flowplayer({
    adaptiveRatio: true
}).onStart(function() { alert('movie has started'); });

OR或者

$("#my-player").flowplayer({
    adaptiveRatio: true,
    clip: {
        onStart: function() { alert('movie has started'); }
    }
});

with no luck whatsoever.没有任何运气。 In my first try onStart doesn't fire, in the rest I get a Javascript "unexpected" error.在我第一次尝试onStart没有触发,在其余的尝试中,我收到了 Javascript“意外”错误。

How do I add onStart in my code sample?如何在我的代码示例中添加onStart (which is a valid way to initialize Flowplayer, since I've found it somewhere in their documentation, labeled "manual setup" - as opposed to not setting anything and just giving the "flowplayer" class in the html markup). (这是一种初始化 Flowplayer 的有效方法,因为我在他们的文档中的某处找到了它,标记为“手动设置”——而不是不设置任何内容而只在 html 标记中给出“flowplayer”类)。 I've searched for an hour and can't find the right sample to be able to add onStart to Flowplayer.我已经搜索了一个小时,但找不到合适的示例来将onStart添加到 Flowplayer。

Also, does initializing like this flowplayer("player", "flowplayer-3.2.18.swf", {});此外,是否像这样初始化flowplayer("player", "flowplayer-3.2.18.swf", {}); mean it uses flash automatically, no html5, regardless whether or not html5 is supported?意味着它自动使用flash,没有html5,无论是否支持html5?

(I'm assuming that you're using FlowPlayer 5.) (我假设您使用的是 FlowPlayer 5。)

To bind JavaScript functions to FlowPlayer events, you need to get a hold of the API for your given player, as is described here: https://flowplayer.org/docs/api.html要将 JavaScript 函数绑定到 FlowPlayer 事件,您需要获取给定播放器的 API,如下所述: https : //flowplayer.org/docs/api.html

Among other things, the page contains a list of all available events.除其他外,该页面包含所有可用事件的列表。 Notably, there is no "start" event, but I've found that "load" does the job just fine.值得注意的是,没有“开始”事件,但我发现“加载”可以很好地完成这项工作。 "finish" and "unload" seem to do the same in the setups I've tried so far (I'm using the splash screen configuration exclusively). “完成”和“卸载”似乎在我迄今为止尝试过的设置中做同样的事情(我只使用启动画面配置)。

An example of that might look like this:一个例子可能如下所示:

<script type="text/javascript">
    // bind your player to a var
    var player = $('#something');

    // initialize the player
    player.flowplayer();

    // bind the api to a var - you can do this only after you have initialized it
    var api = player.data('flowplayer');

    // now we can bind events to the player via the api
    api.bind('load', function(){
        // do something when the video starts
    })
</script>

I'm using flowplayer 7, Javascript implementation:我正在使用 flowplayer 7,Javascript 实现:

<div id="video"></div>
<script>
    var container = document.getElementById("video");
    flowplayer(container, {
        clip: {
            sources: [
                {
                    type: "video/mp4",
                    src: "https://s3.amazonaws.co.....mp4"
                }
            ]
        }
    }).on("resume", function (e, api) {
        console.log("play");
    }).on("pause", function (e, api) {
        console.log("pause");
    });
</script>

so, to add an action when the video start playing you have to bind the "resume" method.因此,要在视频开始播放时添加动作,您必须绑定“resume”方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM