2021-04-01 15:13:35 +00:00
|
|
|
<template>
|
2021-05-06 17:30:02 +00:00
|
|
|
<div class="uk-container-expand">
|
2021-06-22 09:49:14 +00:00
|
|
|
<div
|
|
|
|
data-shaka-player-container
|
2021-08-04 05:13:22 +00:00
|
|
|
style="width: 100%; height: 100%; background: #000"
|
|
|
|
:style="!isEmbed ? { 'max-height': '75vh', 'min-height': '250px' } : {}"
|
2021-06-22 09:49:14 +00:00
|
|
|
ref="container"
|
|
|
|
>
|
2021-07-04 18:42:10 +00:00
|
|
|
<video
|
|
|
|
data-shaka-player
|
|
|
|
class="uk-width-expand"
|
|
|
|
:autoplay="shouldAutoPlay"
|
|
|
|
:loop="selectedAutoLoop"
|
|
|
|
ref="videoEl"
|
|
|
|
></video>
|
2021-05-06 17:30:02 +00:00
|
|
|
</div>
|
2021-04-01 15:13:35 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-07-30 09:34:23 +00:00
|
|
|
<style>
|
|
|
|
.shaka-text-container > div {
|
|
|
|
height: auto !important;
|
|
|
|
width: auto !important;
|
|
|
|
top: auto !important;
|
|
|
|
left: auto !important;
|
|
|
|
}
|
2021-07-31 09:39:21 +00:00
|
|
|
|
|
|
|
.shaka-text-container * {
|
|
|
|
background-color: rgba(8, 8, 8, 0.75) !important;
|
|
|
|
color: white !important;
|
|
|
|
}
|
2021-10-04 10:05:53 +00:00
|
|
|
|
|
|
|
.shaka-video-container:-webkit-full-screen {
|
|
|
|
max-height: none !important;
|
|
|
|
}
|
|
|
|
|
2021-07-30 09:34:23 +00:00
|
|
|
</style>
|
|
|
|
|
2021-04-01 15:13:35 +00:00
|
|
|
<script>
|
|
|
|
import("shaka-player/dist/controls.css");
|
|
|
|
const shaka = import("shaka-player/dist/shaka-player.ui.js");
|
2021-06-09 21:21:35 +00:00
|
|
|
import muxjs from "mux.js";
|
|
|
|
window.muxjs = muxjs;
|
2021-04-01 15:13:35 +00:00
|
|
|
|
|
|
|
export default {
|
2021-05-06 17:30:02 +00:00
|
|
|
props: {
|
|
|
|
video: Object,
|
|
|
|
sponsors: Object,
|
|
|
|
selectedAutoPlay: Boolean,
|
2021-07-04 18:42:10 +00:00
|
|
|
selectedAutoLoop: Boolean,
|
2021-08-04 05:13:22 +00:00
|
|
|
isEmbed: Boolean,
|
2021-05-06 17:30:02 +00:00
|
|
|
},
|
2021-07-07 14:18:09 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
player: null,
|
|
|
|
};
|
|
|
|
},
|
2021-05-06 17:30:02 +00:00
|
|
|
computed: {
|
2021-07-04 18:26:02 +00:00
|
|
|
shouldAutoPlay: _this => {
|
|
|
|
return _this.getPreferenceBoolean("playerAutoPlay", true);
|
2021-05-06 17:30:02 +00:00
|
|
|
},
|
2021-07-21 10:48:59 +00:00
|
|
|
preferredVideoCodecs: _this => {
|
|
|
|
var preferredVideoCodecs = [];
|
2021-08-27 07:33:55 +00:00
|
|
|
const enabledCodecs = _this.getPreferenceString("enabledCodecs", "av1,vp9,avc").split(",");
|
2021-07-21 10:48:59 +00:00
|
|
|
|
2021-08-27 07:33:55 +00:00
|
|
|
if (
|
|
|
|
_this.$refs.videoEl.canPlayType('video/mp4; codecs="av01.0.08M.08"') !== "" &&
|
|
|
|
enabledCodecs.includes("av1")
|
|
|
|
)
|
2021-07-21 10:48:59 +00:00
|
|
|
preferredVideoCodecs.push("av01");
|
2021-08-27 07:33:55 +00:00
|
|
|
if (_this.$refs.videoEl.canPlayType('video/webm; codecs="vp9"') !== "" && enabledCodecs.includes("vp9"))
|
|
|
|
preferredVideoCodecs.push("vp9");
|
|
|
|
if (
|
|
|
|
_this.$refs.videoEl.canPlayType('video/mp4; codecs="avc1.4d401f"') !== "" &&
|
|
|
|
enabledCodecs.includes("avc")
|
|
|
|
)
|
2021-07-21 10:48:59 +00:00
|
|
|
preferredVideoCodecs.push("avc1");
|
|
|
|
|
|
|
|
return preferredVideoCodecs;
|
|
|
|
},
|
2021-05-06 17:30:02 +00:00
|
|
|
},
|
2021-07-09 20:55:09 +00:00
|
|
|
mounted() {
|
|
|
|
if (!this.shaka) this.shakaPromise = shaka.then(shaka => shaka.default).then(shaka => (this.shaka = shaka));
|
|
|
|
},
|
2021-05-06 17:30:02 +00:00
|
|
|
methods: {
|
2021-09-05 13:12:27 +00:00
|
|
|
async loadVideo() {
|
2021-06-09 21:21:35 +00:00
|
|
|
const component = this;
|
2021-05-06 17:30:02 +00:00
|
|
|
const videoEl = this.$refs.videoEl;
|
2021-04-01 15:13:35 +00:00
|
|
|
|
2021-05-06 17:30:02 +00:00
|
|
|
videoEl.setAttribute("poster", this.video.thumbnailUrl);
|
2021-04-01 15:13:35 +00:00
|
|
|
|
2021-05-06 17:30:02 +00:00
|
|
|
if (this.$route.query.t) videoEl.currentTime = this.$route.query.t;
|
2021-04-01 15:13:35 +00:00
|
|
|
|
2021-05-06 17:30:02 +00:00
|
|
|
const noPrevPlayer = !this.player;
|
|
|
|
|
|
|
|
var streams = [];
|
|
|
|
|
|
|
|
streams.push(...this.video.audioStreams);
|
|
|
|
streams.push(...this.video.videoStreams);
|
|
|
|
|
2021-07-07 19:34:46 +00:00
|
|
|
const MseSupport = window.MediaSource !== undefined;
|
|
|
|
|
2021-09-02 13:46:27 +00:00
|
|
|
const lbry = this.getPreferenceBoolean("disableLBRY", false)
|
|
|
|
? null
|
|
|
|
: this.video.videoStreams.filter(stream => stream.quality === "LBRY")[0];
|
2021-07-28 08:02:23 +00:00
|
|
|
|
2021-06-09 21:21:35 +00:00
|
|
|
var uri;
|
2021-09-05 13:12:27 +00:00
|
|
|
var mime;
|
2021-06-09 21:21:35 +00:00
|
|
|
|
2021-08-30 15:48:08 +00:00
|
|
|
if (this.video.livestream) {
|
2021-06-09 21:21:35 +00:00
|
|
|
uri = this.video.hls;
|
2021-09-05 13:12:27 +00:00
|
|
|
mime = "application/x-mpegURL";
|
2021-08-30 15:48:08 +00:00
|
|
|
} else if (this.video.audioStreams.length > 0 && !lbry && MseSupport) {
|
2021-08-15 19:54:34 +00:00
|
|
|
if (!this.video.dash) {
|
|
|
|
const dash = require("@/utils/DashUtils.js").default.generate_dash_file_from_formats(
|
|
|
|
streams,
|
|
|
|
this.video.duration,
|
|
|
|
);
|
2021-06-09 21:21:35 +00:00
|
|
|
|
2021-08-15 19:54:34 +00:00
|
|
|
uri = "data:application/dash+xml;charset=utf-8;base64," + btoa(dash);
|
|
|
|
} else uri = this.video.dash;
|
2021-09-05 13:12:27 +00:00
|
|
|
mime = "application/dash+xml";
|
2021-07-28 08:02:23 +00:00
|
|
|
} else if (lbry) {
|
|
|
|
uri = lbry.url;
|
2021-09-02 13:46:27 +00:00
|
|
|
if (this.getPreferenceBoolean("proxyLBRY", false)) {
|
|
|
|
const url = new URL(uri);
|
|
|
|
url.searchParams.set("host", url.host);
|
|
|
|
url.host = new URL(this.video.proxyUrl).host;
|
|
|
|
uri = url.toString();
|
|
|
|
}
|
2021-09-05 13:12:27 +00:00
|
|
|
const contentType = await fetch(uri, {
|
|
|
|
method: "HEAD",
|
|
|
|
}).then(response => response.headers.get("Content-Type"));
|
|
|
|
mime = contentType;
|
2021-06-18 13:20:41 +00:00
|
|
|
} else {
|
2021-07-10 19:59:21 +00:00
|
|
|
uri = this.video.videoStreams.filter(stream => stream.codec == null).slice(-1)[0].url;
|
2021-09-05 13:12:27 +00:00
|
|
|
mime = "video/mp4";
|
2021-06-09 21:21:35 +00:00
|
|
|
}
|
2021-05-06 17:30:02 +00:00
|
|
|
|
|
|
|
if (noPrevPlayer)
|
2021-07-09 20:55:09 +00:00
|
|
|
this.shakaPromise.then(() => {
|
|
|
|
this.shaka.polyfill.installAll();
|
|
|
|
|
|
|
|
const localPlayer = new this.shaka.Player(videoEl);
|
2021-09-05 13:12:27 +00:00
|
|
|
const proxyHost = new URL(component.video.proxyUrl).host;
|
2021-07-09 20:55:09 +00:00
|
|
|
|
|
|
|
localPlayer.getNetworkingEngine().registerRequestFilter((_type, request) => {
|
|
|
|
const uri = request.uris[0];
|
|
|
|
var url = new URL(uri);
|
2021-09-05 13:12:27 +00:00
|
|
|
const headers = request.headers;
|
|
|
|
if (
|
|
|
|
url.host.endsWith(".googlevideo.com") ||
|
|
|
|
(url.host.endsWith(".lbryplayer.xyz") &&
|
|
|
|
(component.getPreferenceBoolean("proxyLBRY", false) || headers.Range))
|
|
|
|
) {
|
2021-07-09 20:55:09 +00:00
|
|
|
url.searchParams.set("host", url.host);
|
2021-09-05 13:12:27 +00:00
|
|
|
url.host = proxyHost;
|
2021-07-09 20:55:09 +00:00
|
|
|
request.uris[0] = url.toString();
|
|
|
|
}
|
2021-08-25 20:32:56 +00:00
|
|
|
if (url.pathname === "/videoplayback") {
|
|
|
|
if (headers.Range) {
|
|
|
|
url.searchParams.set("range", headers.Range.split("=")[1]);
|
|
|
|
request.headers = {};
|
|
|
|
request.uris[0] = url.toString();
|
|
|
|
}
|
|
|
|
}
|
2021-07-09 20:55:09 +00:00
|
|
|
});
|
2021-06-09 21:21:35 +00:00
|
|
|
|
2021-07-09 20:55:09 +00:00
|
|
|
localPlayer.configure(
|
|
|
|
"streaming.bufferingGoal",
|
|
|
|
Math.max(this.getPreferenceNumber("bufferGoal", 10), 10),
|
|
|
|
);
|
2021-06-22 10:54:20 +00:00
|
|
|
|
2021-09-05 13:12:27 +00:00
|
|
|
this.setPlayerAttrs(localPlayer, videoEl, uri, mime, this.shaka);
|
2021-07-09 20:55:09 +00:00
|
|
|
});
|
2021-09-05 13:12:27 +00:00
|
|
|
else this.setPlayerAttrs(this.player, videoEl, uri, mime, this.shaka);
|
2021-05-06 17:30:02 +00:00
|
|
|
|
|
|
|
if (noPrevPlayer) {
|
|
|
|
videoEl.addEventListener("timeupdate", () => {
|
|
|
|
if (this.sponsors && this.sponsors.segments) {
|
|
|
|
const time = videoEl.currentTime;
|
|
|
|
this.sponsors.segments.map(segment => {
|
2021-07-07 22:21:44 +00:00
|
|
|
if (!segment.skipped || this.selectedAutoLoop) {
|
2021-05-06 17:30:02 +00:00
|
|
|
const end = segment.segment[1];
|
|
|
|
if (time >= segment.segment[0] && time < end) {
|
|
|
|
console.log("Skipped segment at " + time);
|
|
|
|
videoEl.currentTime = end;
|
|
|
|
segment.skipped = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
videoEl.addEventListener("volumechange", () => {
|
2021-07-04 18:26:02 +00:00
|
|
|
this.setPreference("volume", videoEl.volume);
|
2021-05-06 17:30:02 +00:00
|
|
|
});
|
|
|
|
|
2021-10-03 19:18:04 +00:00
|
|
|
videoEl.addEventListener("ratechange", () => {
|
|
|
|
this.setPreference("rate", videoEl.playbackRate);
|
|
|
|
})
|
|
|
|
|
2021-05-06 17:30:02 +00:00
|
|
|
videoEl.addEventListener("ended", () => {
|
2021-07-04 18:42:10 +00:00
|
|
|
if (!this.selectedAutoLoop && this.selectedAutoPlay && this.video.relatedStreams.length > 0) {
|
2021-06-24 18:39:22 +00:00
|
|
|
const params = this.$route.query;
|
|
|
|
let url = this.video.relatedStreams[0].url;
|
|
|
|
const searchParams = new URLSearchParams();
|
|
|
|
for (var param in params)
|
|
|
|
switch (param) {
|
|
|
|
case "v":
|
|
|
|
case "t":
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
searchParams.set(param, params[param]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const paramStr = searchParams.toString();
|
|
|
|
if (paramStr.length > 0) url += "&" + paramStr;
|
|
|
|
this.$router.push(url);
|
|
|
|
}
|
2021-05-06 17:30:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: Add sponsors on seekbar: https://github.com/ajayyy/SponsorBlock/blob/e39de9fd852adb9196e0358ed827ad38d9933e29/src/js-components/previewBar.ts#L12
|
|
|
|
},
|
2021-09-05 13:12:27 +00:00
|
|
|
setPlayerAttrs(localPlayer, videoEl, uri, mime, shaka) {
|
2021-06-07 19:22:29 +00:00
|
|
|
if (!this.ui) {
|
|
|
|
this.ui = new shaka.ui.Overlay(localPlayer, this.$refs.container, videoEl);
|
|
|
|
|
|
|
|
const config = {
|
2021-07-22 20:14:16 +00:00
|
|
|
overflowMenuButtons: ["quality", "captions", "picture_in_picture", "playback_rate", "airplay"],
|
2021-06-07 19:22:29 +00:00
|
|
|
seekBarColors: {
|
|
|
|
base: "rgba(255, 255, 255, 0.3)",
|
|
|
|
buffered: "rgba(255, 255, 255, 0.54)",
|
|
|
|
played: "rgb(255, 0, 0)",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
this.ui.configure(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
const player = this.ui.getControls().getPlayer();
|
|
|
|
|
|
|
|
this.player = player;
|
|
|
|
|
2021-07-03 19:24:09 +00:00
|
|
|
const disableVideo = this.getPreferenceBoolean("listen", false) && !this.video.livestream;
|
2021-07-15 08:41:36 +00:00
|
|
|
|
|
|
|
this.player.configure({
|
2021-07-21 10:48:59 +00:00
|
|
|
preferredVideoCodecs: this.preferredVideoCodecs,
|
2021-07-15 08:41:36 +00:00
|
|
|
preferredAudioCodecs: ["opus", "mp4a"],
|
|
|
|
manifest: {
|
|
|
|
disableVideo: disableVideo,
|
|
|
|
},
|
|
|
|
});
|
2021-06-07 20:35:45 +00:00
|
|
|
|
2021-07-04 18:26:02 +00:00
|
|
|
const quality = this.getPreferenceNumber("quality", 0);
|
2021-07-15 08:41:36 +00:00
|
|
|
const qualityConds =
|
|
|
|
quality > 0 && (this.video.audioStreams.length > 0 || this.video.livestream) && !disableVideo;
|
2021-06-21 20:03:11 +00:00
|
|
|
if (qualityConds) this.player.configure("abr.enabled", false);
|
|
|
|
|
2021-09-05 13:12:27 +00:00
|
|
|
player.load(uri, 0, mime).then(() => {
|
2021-06-21 20:03:11 +00:00
|
|
|
if (qualityConds) {
|
|
|
|
var leastDiff = Number.MAX_VALUE;
|
|
|
|
var bestStream = null;
|
|
|
|
player
|
|
|
|
.getVariantTracks()
|
|
|
|
.sort((a, b) => a.bandwidth - b.bandwidth)
|
|
|
|
.forEach(stream => {
|
|
|
|
const diff = Math.abs(quality - stream.height);
|
|
|
|
if (diff < leastDiff) {
|
|
|
|
leastDiff = diff;
|
|
|
|
bestStream = stream;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
player.selectVariantTrack(bestStream);
|
|
|
|
}
|
|
|
|
|
2021-05-06 17:30:02 +00:00
|
|
|
this.video.subtitles.map(subtitle => {
|
|
|
|
player.addTextTrackAsync(
|
|
|
|
subtitle.url,
|
|
|
|
subtitle.code,
|
|
|
|
"SUBTITLE",
|
|
|
|
subtitle.mimeType,
|
|
|
|
null,
|
|
|
|
subtitle.name,
|
|
|
|
);
|
|
|
|
});
|
2021-07-04 18:26:02 +00:00
|
|
|
videoEl.volume = this.getPreferenceNumber("volume", 1);
|
2021-10-03 19:18:04 +00:00
|
|
|
videoEl.playbackRate = this.getPreferenceNumber("rate", 1);
|
2021-05-06 17:30:02 +00:00
|
|
|
});
|
|
|
|
},
|
2021-09-05 20:53:59 +00:00
|
|
|
destroy() {
|
|
|
|
if (this.ui) {
|
|
|
|
this.ui.destroy();
|
|
|
|
this.ui = undefined;
|
|
|
|
this.player = undefined;
|
|
|
|
}
|
|
|
|
if (this.player) {
|
|
|
|
this.player.destroy();
|
|
|
|
this.player = undefined;
|
|
|
|
}
|
|
|
|
if (this.hotkeys) this.hotkeys.unbind();
|
|
|
|
if (this.$refs.container) this.$refs.container.querySelectorAll("div").forEach(node => node.remove());
|
|
|
|
},
|
2021-05-06 17:30:02 +00:00
|
|
|
},
|
2021-07-07 14:18:09 +00:00
|
|
|
activated() {
|
2021-06-01 09:19:01 +00:00
|
|
|
import("hotkeys-js")
|
|
|
|
.then(mod => mod.default)
|
|
|
|
.then(hotkeys => {
|
|
|
|
this.hotkeys = hotkeys;
|
|
|
|
var self = this;
|
2021-08-16 12:50:25 +00:00
|
|
|
hotkeys("f,m,j,k,l,space,up,down,left,right", function(e, handler) {
|
2021-06-01 09:19:01 +00:00
|
|
|
const videoEl = self.$refs.videoEl;
|
|
|
|
switch (handler.key) {
|
|
|
|
case "f":
|
2021-09-22 14:03:57 +00:00
|
|
|
self.ui.getControls().toggleFullScreen();
|
2021-06-01 09:19:01 +00:00
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "m":
|
|
|
|
videoEl.muted = !videoEl.muted;
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
2021-08-16 12:50:25 +00:00
|
|
|
case "j":
|
|
|
|
videoEl.currentTime = Math.max(videoEl.currentTime - 15, 0);
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "l":
|
|
|
|
videoEl.currentTime = videoEl.currentTime + 15;
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "k":
|
2021-06-01 09:19:01 +00:00
|
|
|
case "space":
|
|
|
|
if (videoEl.paused) videoEl.play();
|
|
|
|
else videoEl.pause();
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "up":
|
|
|
|
videoEl.volume = Math.min(videoEl.volume + 0.05, 1);
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "down":
|
|
|
|
videoEl.volume = Math.max(videoEl.volume - 0.05, 0);
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "left":
|
|
|
|
videoEl.currentTime = Math.max(videoEl.currentTime - 5, 0);
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "right":
|
|
|
|
videoEl.currentTime = videoEl.currentTime + 5;
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2021-04-03 15:45:45 +00:00
|
|
|
},
|
2021-07-07 14:18:09 +00:00
|
|
|
deactivated() {
|
2021-09-05 20:53:59 +00:00
|
|
|
this.destroy();
|
|
|
|
},
|
|
|
|
unmounted() {
|
|
|
|
this.destroy();
|
2021-04-07 11:45:40 +00:00
|
|
|
},
|
2021-04-01 15:13:35 +00:00
|
|
|
};
|
|
|
|
</script>
|