Skip to content

Instantly share code, notes, and snippets.

@CoolS2
Created July 21, 2016 06:53
Show Gist options
  • Select an option

  • Save CoolS2/3511dd2e88829f88877aabf81d63fa28 to your computer and use it in GitHub Desktop.

Select an option

Save CoolS2/3511dd2e88829f88877aabf81d63fa28 to your computer and use it in GitHub Desktop.
flowplayer(function (api, root) {
var fsbutton = document.createElement("a"),
anchors = root.getElementsByTagName("a"),
divs = root.getElementsByTagName("div"),
i, elem;
fsbutton.className = "fp-fullscreen";
for (i = 0; i < anchors.length; i += 1) {
elem = anchors[i];
if (elem.className == "fp-fullscreen") {
elem.parentNode.removeChild(elem);
break;
}
}
for (i = 0; i < divs.length; i += 1) {
elem = divs[i];
if (elem.className == "fp-controls") {
elem.appendChild(fsbutton);
break;
}
}
});
var container = document.getElementById("live"),
timer,
player = flowplayer(container,{
live: true,
//key:"$153760428632348",
autoplay:true,
fullscreen:true,
native_fullscreen:true,
clip: {
hlsjs: {
// listen to hls.js ERROR
listeners: ["hlsError"],
// limit amount of hls level loading retries
levelLoadingMaxRetry: 2
},
flashls: {
// limit amount of retries to load hls manifests in Flash
manifestloadmaxretry: 2
},
sources: [
{
type: "application/x-mpegurl",
src: "<?php print($cam.'?token='.$token) ?>"
}
]
}
}).on("load", function (e, api, video) {
clearInterval(timer);
}).on("error", function (e, api, err) {
var delay = 20,
header = container.querySelector(".fp-message h2"),
detail = container.querySelector(".fp-message p");
detail.style.display = 'none';
if (err.code === 4 || err.code === 9) {
header.innerHTML = "<?php pll_e('Video_error');?>";
if (flowplayer.support.flashVideo) {
api.one("flashdisabled", function () {
container.querySelector(".fp-flash-disabled").style.display = "none";
});
}
timer = setInterval(function () {
delay -= 1;
// detail.querySelector("span").innerHTML = delay;
if (!delay) {
clearInterval(timer);
api.error = api.loading = false;
container.className = container.className.replace(/ *is-error */, "");
api.load(api.conf.clip);
}
}, 1000);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment