How to pass stream from php link to clappr player?

625 views Asked by At

I have a php link that return the url of stream like this: https://myexample.com/test.php?id=xyz

<?php
//declare some headers and variables
$_GET["id"];
//Do some curl here
$stream = $result;
echo $stream; //http://myexample.com/xyz.m3u8?token=xxx
?>

I would to pass the result of the php link to the my video page that contain clappr player. How do I define the variable src to get the stream link from the php response in the script? I did this way but not working.

<div id="player">
</div>
<script>
    var src="https://myexample.com/test.php?id=xyz";
    var player = new Clappr.Player({source: src, 
    autoPlay: true,
    height: 360,
    width: '100%',
    parentId: "#player"
});
  </script>

Please help!

1

There are 1 answers

1
Sunny bhatti On

This will work only if javascript is placed in the same file:

<?php $stream = "http://myexample.com/xyz.m3u8?token=xxx"; ?>
var src="<?php echo $stream; ?>";