我需要包含此 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');
(结果类似于:http://stream.com/live/livestream.m3u8)
这里...
<script src="clappr.min.js"></script>
<script>var player = new Clappr.Player({source: "RESULT HERE"});</script>
如何包含结果?用document.write?或者我也应该使用 PHP?
最佳答案
你就不能这样做吗?
<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>
关于javascript - 如何将 JavaScript 结果包含到播放器中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60194944/