Joan Rius Canalda
Joan Rius Canalda

Reputation: 11

How to include the JavaScript result into the player?

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?

Upvotes: 1

Views: 451

Answers (2)

Jeff Mergler
Jeff Mergler

Reputation: 1532

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"});

Upvotes: 0

Jakob F
Jakob F

Reputation: 1056

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>

Upvotes: 0

Related Questions