Fix video autoplay on page load — trigger play on MANIFEST_PARSED
Previously, play() was only called from the canplay listener which can fire too late or be missed with HLS.js. Now also triggers on Hls.Events.MANIFEST_PARSED (the earliest reliable point), and calls play() directly after video.load() for MP4/native-HLS paths. Also fixes _ytpLoadSource (SPA transitions) to use the same pattern. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4f275de15f
commit
e74862a24d
@ -808,34 +808,55 @@ function getShuffledPrevUrl() {
|
||||
|
||||
window._ytpHls = null;
|
||||
|
||||
function tryAutoplay() {
|
||||
video.muted = true;
|
||||
video.autoplay = true;
|
||||
video.play().catch(function(){});
|
||||
}
|
||||
|
||||
function initSource() {
|
||||
video.muted = true;
|
||||
video.autoplay = true;
|
||||
if (HLS_URL && window.Hls && Hls.isSupported()) {
|
||||
window._ytpHls = new Hls({ startLevel: -1 });
|
||||
window._ytpHls.loadSource(HLS_URL);
|
||||
window._ytpHls.attachMedia(video);
|
||||
window._ytpHls.once(Hls.Events.MANIFEST_PARSED, tryAutoplay);
|
||||
} else if (HLS_URL && video.canPlayType('application/vnd.apple.mpegurl')) {
|
||||
video.src = HLS_URL;
|
||||
video.load();
|
||||
video.play().catch(function(){});
|
||||
} else {
|
||||
video.src = MP4_URL;
|
||||
video.load();
|
||||
video.play().catch(function(){});
|
||||
}
|
||||
}
|
||||
|
||||
// Reinitialize source after SPA transition — called by playlist overlay scripts
|
||||
window._ytpLoadSource = function(hlsUrl, mp4Url) {
|
||||
if (window._ytpHls) { window._ytpHls.destroy(); window._ytpHls = null; }
|
||||
video.muted = true;
|
||||
video.autoplay = true;
|
||||
if (hlsUrl && window.Hls && Hls.isSupported()) {
|
||||
window._ytpHls = new Hls({ startLevel: -1 });
|
||||
window._ytpHls.loadSource(hlsUrl);
|
||||
window._ytpHls.attachMedia(video);
|
||||
window._ytpHls.once(Hls.Events.MANIFEST_PARSED, function() {
|
||||
video.muted = false;
|
||||
video.play().catch(function(){});
|
||||
});
|
||||
} else if (hlsUrl && video.canPlayType('application/vnd.apple.mpegurl')) {
|
||||
video.src = hlsUrl;
|
||||
video.load();
|
||||
video.muted = false;
|
||||
video.play().catch(function(){});
|
||||
} else {
|
||||
video.src = mp4Url;
|
||||
video.load();
|
||||
video.muted = false;
|
||||
video.play().catch(function(){});
|
||||
}
|
||||
video.muted = false;
|
||||
video.play().catch(function(){});
|
||||
};
|
||||
|
||||
// Load HLS.js from CDN then init
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user