如何使用JavaScript自动播放锚标记

时间:2014-08-08 08:44:26

标签: javascript hyperlink jwplayer6

我有一个播放器和一个锚点作为按钮。当我点击按钮时,我通过JavaScript获取其ID并将其发送到服务器。我从服务器上取回,应该开始在播放器中播放的URL。 (我正在使用jwplayer)我有义务使用链接为Android版本的页面,因为jwplayer没有正确覆盖它。但是我还需要使用令牌来保护我的流,这就是为什么每次点击按钮时我都应该从服务器上获取新流。

我的问题是,从服务器上取下后,我不知道如何播放流。 示例代码:

    <div id="myElement">Loading the player...</div><br><br>
    <a     href="javascript:loadVideos('http://content.jwplatform.com/manifests/bkaovAYt.smil','http:/    /content.jwplatform.com/manifests/bkaovAYt.m3u8');">Big Buck Bunny trailer</a><br><br>
    <a     href="javascript:loadVideos('http://content.jwplatform.com/manifests/i8oQD9zd.smil','http:/    /content.jwplatform.com/manifests/i8oQD9zd.m3u8');
">Tears of Steel trailer</a><br><br>
<script type="text/javascript"> 
jwplayer("myElement").setup({
    playlist: [{
        image: 'bunny.jpg',
        sources: [{
            file: 'http://content.jwplatform.com/manifests/bkaovAYt.smil'
        },{
            file: 'http://content.jwplatform.com/manifests/bkaovAYt.m3u8'
        }]
    }],
    height: '450',
    width: '800',
    androidhls: 'true'
}); 

function loadVideos(rtmp,hls) {
    jwplayer().load([{
        sources: [{
            file: rtmp
        },{
            file: hls
        }]
    }]);
    jwplayer().play();
} 
</script>

我想要实现的目标是:

<div id="myElement">Loading the player...</div><br><br>
<a href="javascript:loadVideos(data,data1);">Big Buck Bunny trailer</a><br><br>
<a href="javascript:loadVideos(data,data1);
">Tears of Steel trailer</a><br><br>
<script type="text/javascript"> 
jwplayer("myElement").setup({
    playlist: [{
        image: 'bunny.jpg',
        sources: [{
            file: 'http://content.jwplatform.com/manifests/bkaovAYt.smil'
        },{
            file: 'http://content.jwplatform.com/manifests/bkaovAYt.m3u8'
        }]
    }],
    height: '450',
    width: '800',
    androidhls: 'true'
}); 

function loadVideos(rtmp,hls) {
    jwplayer().load([{
        sources: [{
            file: rtmp
        },{
            file: hls
        }]
    }]);
    jwplayer().play();
} 
</script>

&#39;数据&#39;和&#39; data1&#39;将是从服务器发回的URL。 一旦答案回来,用户将单击该按钮,这将导致对服务器的呼叫。我该怎么玩?

我希望我能从你们那里得到一些建议。

亲切的问候!

0 个答案:

没有答案