Update css/player-base.js

This commit is contained in:
ashley 2025-08-27 14:00:22 +02:00
parent 9774115145
commit 9c2f39455f

View File

@ -1,65 +1,70 @@
// in the beginning.... god made mrrprpmnaynayaynaynayanyuwuuuwmauwnwanwaumawp :p // in the beginning.... god made mrrprpmnaynayaynaynayanyuwuuuwmauwnwanwaumawp :p
var _yt_player = videojs; var _yt_player = videojs;
// DASH.js + Video.js + quality menu
// - Uses global window.mpdurl (YouTube DASH MPD URL)
// - Starts in HD by default (high initial bitrate), then ABR can adapt
// - Adds a Quality menu (manual override) via contrib-quality-levels + http-source-selector
// - Wipes any saved progress key `progress-<v>` as you asked
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const qs = new URLSearchParams(location.search); // nuke progress key like progress-<videoId>
const qs = new URLSearchParams(location.search);
const vidKey = qs.get('v') || ''; const vidKey = qs.get('v') || '';
if (vidKey) { try { localStorage.removeItem(`progress-${vidKey}`); } catch {} } if (vidKey) { try { localStorage.removeItem(`progress-${vidKey}`); } catch {} }
// guard: require mpdurl
const MPD_URL = (typeof window !== 'undefined' && window.mpdurl) ? String(window.mpdurl) : ''; const MPD_URL = (typeof window !== 'undefined' && window.mpdurl) ? String(window.mpdurl) : '';
if (!MPD_URL) { console.error('[dash] window.mpdurl is not set'); return; } if (!MPD_URL) { console.error('[dash] window.mpdurl is not set'); return; }
// init Video.js
const player = videojs('video', { const player = videojs('video', {
controls: true, controls: true,
autoplay: false, autoplay: false,
preload: 'auto' preload: 'auto'
}); });
// add quality menu (reads available DASH reps through quality-levels) // load DASH source
// plugin injects its own button; no addChild is needed
if (typeof player.httpSourceSelector === 'function') {
player.httpSourceSelector({ default: 'auto' });
}
// set the MPD (dash.js attaches via videojs-contrib-dash)
player.ready(() => { player.ready(() => {
player.src({ src: MPD_URL, type: 'application/dash+xml' }); player.src({ src: MPD_URL, type: 'application/dash+xml' });
});
// when dash.js is fully wired, set HD as the initial default // --- HD Button component ---
// Use dash.js Settings: initialBitrate.video in kbps (keep ABR enabled) const Button = videojs.getComponent('Button');
// ref: dash.js Settings initialBitrate/autoSwitchBitrate docs. :contentReference[oaicite:0]{index=0} const HDButton = videojs.extend(Button, {
const applyHDDefault = () => { constructor: function() {
Button.apply(this, arguments);
this.controlText("Force HD");
this.addClass('vjs-hd-button');
this.addClass('vjs-control');
},
handleClick: function() {
try { try {
const dash = player.dash && player.dash.mediaPlayer; // dash.js instance exposed by contrib-dash. :contentReference[oaicite:1]{index=1} const dash = player.dash && player.dash.mediaPlayer;
if (!dash || typeof dash.updateSettings !== 'function') return; if (!dash) return;
// Pick a "HD-ish" starting point; YouTube MPDs typically have > 2.5Mbps for 720p and up. // get available video qualities
// Adjust if you want to bias higher/lower. const q = dash.getBitrateInfoListFor('video') || [];
if (q.length === 0) return;
// highest quality index
const maxIndex = q.length - 1;
// lock to highest rep
dash.updateSettings({ dash.updateSettings({
streaming: { streaming: {
abr: { abr: {
initialBitrate: { video: 5000, audio: -1 }, // ~5 Mbps start → choose an HD rep first autoSwitchBitrate: { video: false }, // disable ABR
autoSwitchBitrate: { video: true, audio: true } // keep ABR on after start
} }
} }
}); });
} catch {} dash.setQualityFor('video', maxIndex);
};
// call once the tech is up; 'loadedmetadata' is a safe point // visual feedback: briefly change button text
player.one('loadedmetadata', applyHDDefault); const old = this.el().textContent;
this.el().textContent = "HD✓";
setTimeout(() => { this.el().textContent = old; }, 1500);
} catch (e) { console.error("HD force failed", e); }
}
}); });
// tiny invisible retry for transient net/decode stalls (same MPD; no fallbacks) // register and add to control bar
videojs.registerComponent('HDButton', HDButton);
player.getChild('controlBar').addChild('HDButton', {}, player.getChild('controlBar').children().length - 1);
// --- retry logic stays same ---
player.on('error', () => { player.on('error', () => {
const err = player.error(); const err = player.error();
if (!err || err.code === 2 || err.code === 3) { if (!err || err.code === 2 || err.code === 3) {
@ -78,7 +83,6 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
// hai!! if ur asking why are they here - its for smth in the future!!!!!! // hai!! if ur asking why are they here - its for smth in the future!!!!!!
const FORMATS = { const FORMATS = {