Update css/player-base.js
This commit is contained in:
parent
cd49fb9954
commit
bf2532ee48
@ -1,8 +1,12 @@
|
|||||||
// in the beginning.... god made mrrprpmnaynayaynaynayanyuwuuuwmauwnwanwaumawp :p
|
// in the beginning.... god made mrrprpmnaynayaynaynayanyuwuuuwmauwnwanwaumawp :p
|
||||||
var _yt_player = videojs;
|
var _yt_player = videojs;
|
||||||
|
|
||||||
|
|
||||||
|
// Video.js + dash.js (videojs-contrib-dash)
|
||||||
|
// Goal: Prefer HD automatically, but allow ABR to adapt (drop/raise) if bandwidth requires.
|
||||||
|
// Uses global window.mpdurl for the MPD URL.
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
// nuke progress key like progress-<videoId>
|
|
||||||
const qs = new URLSearchParams(location.search);
|
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 {} }
|
||||||
@ -10,6 +14,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
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,
|
||||||
@ -19,52 +24,53 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
// load DASH source
|
// load DASH source
|
||||||
player.ready(() => {
|
player.ready(() => {
|
||||||
player.src({ src: MPD_URL, type: 'application/dash+xml' });
|
player.src({ src: MPD_URL, type: 'application/dash+xml' });
|
||||||
});
|
|
||||||
|
|
||||||
// --- HD Button component ---
|
// Prefer HD at start, but let ABR auto-adapt afterward
|
||||||
const Button = videojs.getComponent('Button');
|
player.one('loadedmetadata', () => {
|
||||||
const HDButton = videojs.extend(Button, {
|
|
||||||
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;
|
const dash = player.dash && player.dash.mediaPlayer;
|
||||||
if (!dash) return;
|
if (!dash) return;
|
||||||
|
|
||||||
// get available video qualities
|
// 1) Bias startup toward HD:
|
||||||
const q = dash.getBitrateInfoListFor('video') || [];
|
// - Use a high initialBitrate so the first pick tends to be HD
|
||||||
if (q.length === 0) return;
|
// - Temporarily disable ABR to *force* the highest rep just once
|
||||||
|
|
||||||
// highest quality index
|
|
||||||
const maxIndex = q.length - 1;
|
|
||||||
|
|
||||||
// lock to highest rep
|
|
||||||
dash.updateSettings({
|
dash.updateSettings({
|
||||||
streaming: {
|
streaming: {
|
||||||
abr: {
|
abr: {
|
||||||
autoSwitchBitrate: { video: false }, // disable ABR
|
initialBitrate: { video: 8000, audio: -1 }, // ~8 Mbps target for initial HD pick
|
||||||
|
autoSwitchBitrate: { video: false, audio: true } // pause ABR for a moment (video only)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dash.setQualityFor('video', maxIndex);
|
|
||||||
|
|
||||||
// visual feedback: briefly change button text
|
// Force highest representation once
|
||||||
const old = this.el().textContent;
|
const levels = dash.getBitrateInfoListFor('video') || [];
|
||||||
this.el().textContent = "HD✓";
|
if (levels.length > 0) {
|
||||||
setTimeout(() => { this.el().textContent = old; }, 1500);
|
const maxIndex = levels.length - 1;
|
||||||
} catch (e) { console.error("HD force failed", e); }
|
dash.setQualityFor('video', maxIndex);
|
||||||
}
|
// Optional: also lift any portal cap
|
||||||
|
dash.updateSettings({ streaming: { abr: { limitBitrateByPortal: false } } });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) Re-enable ABR shortly after so it can drop/raise based on network conditions
|
||||||
|
setTimeout(() => {
|
||||||
|
try {
|
||||||
|
dash.updateSettings({
|
||||||
|
streaming: {
|
||||||
|
abr: {
|
||||||
|
autoSwitchBitrate: { video: true, audio: true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch {}
|
||||||
|
}, 1200); // small delay lets the HD buffer initialize before ABR can adjust
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[dash] HD preference setup failed:', e);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// register and add to control bar
|
// Quiet retry for transient stalls (same MPD, no alternates)
|
||||||
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) {
|
||||||
@ -82,6 +88,7 @@ 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!!!!!!
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user