How to include the JavaScript result into the player?

436 Views Asked by At

I need to include the result of this JavaScript.

<script>
function file_get_contents(filename) {
fetch(filename).then((resp) => resp.text()).then(function(data) {
    url = JSON.parse(data)
    location.replace(url['stream]);
});
}
file_get_contents('http://api.stream.com/live');

(The result is something like: http://stream.com/live/livestream.m3u8)

here...

<script src="clappr.min.js"></script>
<script>var player = new Clappr.Player({source: "RESULT HERE"});</script>

How do I include the result? With document.write? Or should I use PHP too?

2

There are 2 best solutions below

1
On

According to the documentation https://clappr.github.io/classes/Player.html, Clapper player is expecting a string value path that points to an MP4 file:

var player = new Clappr.Player({source: "http://your.video/here.mp4", parentId: "#player"});

What does file_get_contents return?

Have you tried getting the basics to work with a hardcoded MP4?

var player = new Clappr.Player({source: "http://api.stream.com/live/your.mp4", parentId: "#player"});
1
On

Can't you just do this?

<script src="clappr.min.js"></script>
<script>
function file_get_contents(filename) {
    fetch(filename).then((resp) => resp.text()).then(function(data) {
        url = JSON.parse(data)
        location.replace(url['stream]);
    });
}
file_get_contents('http://api.stream.com/live');
var player = new Clappr.Player({source: file_get_contents('http://api.stream.com/live')});
</script>