1

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?

Jeff Mergler
  • 1,384
  • 20
  • 27

2 Answers2

0

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>
Jakob F
  • 1,046
  • 10
  • 23
0

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"});
Jeff Mergler
  • 1,384
  • 20
  • 27
  • Hi Jeff. Clappr supports mp4 or m3u8. "file_get_contents" return a m3u8 (like http://stream.com/live/livestream.m3u8) I have not put the original link because it's geoblocked. – Joan Rius Canalda Feb 12 '20 at 19:52