duanmo6937
duanmo6937
2018-04-03 15:18
浏览 55

如何回显var在下一个代码中? (流网址)

First i convert the url (php string) to jquery array,

And now I need the broadcast to work using the var #url.

Works:

hls.loadSource('http://149.56.21.86:25461/live/demivadoiscar/Quz2LG/158.ts');

Not Works:

hls.loadSource('#url');

-

<?php
$url = "http://149.56.21.86:25461/live/demivadoiscar/Quz2LG/158.ts";
?>

<html>
<body>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<video height="600" id="video" controls></video>

var url = <?php $url?>

<script>
if(Hls.isSupported()){
    var video = document.getElementById('video');
    var hls = new Hls();
    hls.loadSource('#url');
    hls.attachMedia(video);
    hls.on(Hls.Events.MANIFEST_PARSED,function(){
        video.play();
    });
}
</script>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doudiecai1572
    doudiecai1572 2018-04-03 15:21
    已采纳

    try this:

    <script>
        var url = "<?php echo $url; ?>";
        if(Hls.isSupported()){
           var video = document.getElementById('video');
           var hls = new Hls();
           hls.loadSource(url);
           hls.attachMedia(video);
           hls.on(Hls.Events.MANIFEST_PARSED,function(){
              video.play();
           });
        }
    </script>
    
    点赞 评论
  • du0173
    du0173 2018-04-03 15:22

    You need the url to be a string and use it in your load source function like so:

    <script>
    var url = '<?php echo $url; ?>';
    //setup code
    hls.loadSource(url);
    //the rest of the code
    </script>
    
    点赞 评论

相关推荐