1

我有一个播放器和一个锚作为按钮。当我点击按钮时,我通过 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>

'data' 和 'data1' 将是从服务器发回的 URL。一旦答案返回,用户将单击该按钮,这将导致对服务器的调用。我该怎么玩?

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

亲切的问候!

4

0 回答 0