override RemotePlayer
This commit is contained in:
parent
af036abf0d
commit
f201d8e803
@ -2,8 +2,9 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">{% for item in meta %}
|
||||
{% block item %}<meta property="{{ item[0] }}" content="{{ item[1] }}" />{% end %}{% end %}
|
||||
<script async src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"></script>
|
||||
<script async src="https://www.gstatic.com/cast/sdk/libs/sender/1.0/cast_framework.js"></script>
|
||||
<script async src="{{ data["script"] }}"></script>
|
||||
<script async src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"></script>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ data["videojs_version"] }}/video.min.js"></script>
|
||||
<script defer src="https://cdn.jsdelivr.net/npm/@silvermine/videojs-chromecast@{{ data["chromecast_version"] }}/dist/silvermine-videojs-chromecast.min.js"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/{{ data["font_awesome_version"] }}/css/all.min.css">
|
||||
|
@ -1,67 +1,72 @@
|
||||
(() => {
|
||||
let upstream = "{{ stream }}";
|
||||
let xhr = new XMLHttpRequest();
|
||||
const setRemotePlayer = () => {
|
||||
class NewRemotePlayer extends cast.framework.RemotePlayer {
|
||||
constructor() {
|
||||
super();
|
||||
this.canControlVolume = false;
|
||||
}
|
||||
}
|
||||
cast.framework.RemotePlayer = NewRemotePlayer;
|
||||
}
|
||||
|
||||
const upstream = "{{ stream }}";
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("HEAD", upstream, true);
|
||||
xhr.send();
|
||||
|
||||
let count = 2;
|
||||
let handleCount = () => {
|
||||
const handleCount = () => {
|
||||
if(--count === 0) {
|
||||
handle();
|
||||
}
|
||||
}
|
||||
|
||||
let handle = () => {
|
||||
let bodies = document.getElementsByTagName("body");
|
||||
if(bodies.length === 1) {
|
||||
let body = bodies[0];
|
||||
let video = document.createElement("video");
|
||||
video.className = "video-js vjs-big-play-centered";
|
||||
body.appendChild(video);
|
||||
let ctype = xhr.getResponseHeader("Content-Type");
|
||||
console.log(ctype);
|
||||
let options = {};
|
||||
options.controls = true;
|
||||
options.liveui = true;
|
||||
options.responsive = true;
|
||||
options.fill = true;
|
||||
options.techOrder = ["chromecast", "html5"];
|
||||
options.plugins = {};
|
||||
options.plugins.chromecast = {};
|
||||
options.plugins.chromecast.requestTitleFn = (src) => {
|
||||
return "{% raw title %}";
|
||||
}
|
||||
|
||||
let player = videojs(video, options);
|
||||
let source = {};
|
||||
source.type = ctype;
|
||||
source.src = upstream;
|
||||
player.src(source);
|
||||
let Button = videojs.getComponent("Button");
|
||||
let cbutton = {};
|
||||
cbutton.clickHandler = (ev) => {
|
||||
try {
|
||||
player.chromecastSessionManager.remotePlayer.canControlVolume = false;
|
||||
} catch(error) {
|
||||
console.log(error);
|
||||
}
|
||||
player.trigger("chromecastRequested");
|
||||
}
|
||||
let button = new Button(player, cbutton);
|
||||
button.addClass("fab");
|
||||
button.addClass("fa-chromecast");
|
||||
button.addClass("vjs-control");
|
||||
button.addClass("vjs-button");
|
||||
button.addClass("vjs-big-chromecast");
|
||||
|
||||
//player.one("chromecastDevicesAvailable", () => {
|
||||
player.addChild(button);
|
||||
player.one("play", () => {
|
||||
player.removeChild(button);
|
||||
});
|
||||
//});
|
||||
}
|
||||
const handleLoaded = () => {
|
||||
setRemotePlayer();
|
||||
handleCount();
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", handleCount);
|
||||
|
||||
const handle = () => {
|
||||
const [body] = document.getElementsByTagName("body");
|
||||
const video = document.createElement("video");
|
||||
video.className = "video-js vjs-big-play-centered";
|
||||
body.appendChild(video);
|
||||
const ctype = xhr.getResponseHeader("Content-Type");
|
||||
console.log(ctype);
|
||||
const options = {};
|
||||
options.controls = true;
|
||||
options.liveui = true;
|
||||
options.responsive = true;
|
||||
options.fill = true;
|
||||
options.techOrder = ["chromecast", "html5"];
|
||||
options.plugins = {};
|
||||
options.plugins.chromecast = {};
|
||||
options.plugins.chromecast.requestTitleFn = (src) => {
|
||||
return "{% raw title %}";
|
||||
}
|
||||
|
||||
const player = videojs(video, options);
|
||||
const source = {};
|
||||
source.type = ctype;
|
||||
source.src = upstream;
|
||||
player.src(source);
|
||||
const Button = videojs.getComponent("Button");
|
||||
const cbutton = {};
|
||||
cbutton.clickHandler = (ev) => {
|
||||
player.trigger("chromecastRequested");
|
||||
}
|
||||
const button = new Button(player, cbutton);
|
||||
button.addClass("fab");
|
||||
button.addClass("fa-chromecast");
|
||||
button.addClass("vjs-control");
|
||||
button.addClass("vjs-button");
|
||||
button.addClass("vjs-big-chromecast");
|
||||
|
||||
player.addChild(button);
|
||||
player.one("play", () => {
|
||||
player.removeChild(button);
|
||||
});
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", handleLoaded);
|
||||
xhr.addEventListener("load", handleCount);
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user