1
jwplayer("myElement_0").onPlay(function(){ pausePlayers(1); alert('0 has started'); });
jwplayer("myElement_1").onPlay(function(){ pausePlayers(2); alert('1 has started'); });
jwplayer("myElement_2").onPlay(function(){ pausePlayers(3); alert('2 has started'); });
jwplayer("myElement_3").onPlay(function(){ pausePlayers(4); alert('3 has started'); });
function pausePlayers(playing) { 
    for (var i=0; i<4; i++) {
       if(i != playing) { jwplayer("myElement_"+i).pause(true); }
    }
};

如果一个正在运行,我有这个脚本可以暂停其他玩家。但它不起作用。在我的控制台中,我看到:

Uncaught TypeError: Object #<Object> has no method 'onPlay' (anonymous function)

alhouthgh 我很确定 jwplayer 脚本正在加载,没有问题。

4

1 回答 1

0

这是一些快速而肮脏的示例代码,用于类似这样的事情:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <script type="text/javascript" src="http://www.longtailvideo.com/jwplayer/jwplayer.js"></script>
        <title>Multiple Mutually Exclusive JW6 Players Which Stop at End</title>
    </head>
    <body bgcolor="#EEE">
            <div id="container"></div>
            <script type="text/javascript">
            jwplayer("container").setup({
            file: "http://www.longtailvideo.com/jw/upload/bunny.mp4",
            image: "http://www.longtailvideo.com/jw/upload/bunny.jpg",
            height: 200,
            width: 300,
            stretching: "exactfit",
            events:{
                onPlay: function() {
                jwplayer('container2').stop();jwplayer('container3').stop();
                },
                onTime: function(object) {
                if(object.position > object.duration - 1) {this.pause();}
                }
            }
            });
            </script>
            <br />
            <div id="container2"></div>
            <script type="text/javascript">
            jwplayer("container2").setup({
            file: "http://www.longtailvideo.com/jw/upload/bunny.flv",
            image: "http://www.longtailvideo.com/jw/upload/bunny.jpg",
            height: 200,
            width: 300,
            stretching: "exactfit",
            events:{
                onPlay: function() {
                jwplayer('container').stop();jwplayer('container3').stop();
                },
                onTime: function(object) {
                if(object.position > object.duration - 1) {this.pause();}
                }
            }
            });
            </script>
            <br />
            <div id="container3"></div>
            <script type="text/javascript">
            jwplayer("container3").setup({
            file: "http://www.longtailvideo.com/jw/upload/bunny.mov",
            image: "http://www.longtailvideo.com/jw/upload/bunny.jpg",
            primary: "flash",
            height: 200,
            width: 300,
            stretching: "exactfit",
            events:{
                onPlay: function() {
                jwplayer('container').stop();jwplayer('container2').stop();
                },
                onTime: function(object) {
                if(object.position > object.duration - 1) {this.pause();}
                }
            }
            });
            </script>
    </body>
</html>
于 2013-03-22T17:20:11.063 回答