Skip to content

Commit d7b87de

Browse files
committed
fix: delay shell reveal until video is ready
1 parent b16cac7 commit d7b87de

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/ShellVideo/ShellVideo.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ function ShellVideo(options) {
9595
var stream = null;
9696

9797
var avgDuration = 0;
98+
var durationReady = false;
9899
var minClipDuration = 30;
99100

100101
function setBackground(visible) {
@@ -110,6 +111,13 @@ function ShellVideo(options) {
110111
}
111112
}
112113
}
114+
function updateLoaded() {
115+
if (!props.loaded && durationReady && props['video-params'] && props['paused-for-cache'] === false) {
116+
props.loaded = true;
117+
setBackground(false);
118+
onPropChanged('loaded');
119+
}
120+
}
113121
function logProp(args) {
114122
// eslint-disable-next-line no-console
115123
console.log(args.name+': '+args.data);
@@ -143,11 +151,8 @@ function ShellVideo(options) {
143151
// for bitwise maths so the maximum supported video duration is 1073741823 (2 ^ 30 - 1)
144152
// which is around 34 years of playback time.
145153
avgDuration = avgDuration ? (avgDuration + intDuration) >> 1 : intDuration;
146-
props.loaded = intDuration > 0;
147-
if(props.loaded) {
148-
setBackground(false);
149-
onPropChanged('loaded');
150-
}
154+
durationReady = intDuration > 0;
155+
updateLoaded();
151156
break;
152157
}
153158
case 'time-pos': {
@@ -176,6 +181,10 @@ function ShellVideo(options) {
176181
case 'paused-for-cache':
177182
case 'seeking':
178183
{
184+
if (args.name === 'paused-for-cache') {
185+
props[args.name] = args.data;
186+
updateLoaded();
187+
}
179188
if(props.buffering !== args.data) {
180189
props.buffering = args.data;
181190
onPropChanged('buffering');
@@ -196,6 +205,7 @@ function ShellVideo(options) {
196205
}
197206
case 'video-params': {
198207
props[args.name] = args.data;
208+
updateLoaded();
199209
var params = args.data || {};
200210
var gamma = typeof params.gamma === 'string' ? params.gamma : null;
201211
if (gamma === 'pq' || gamma === 'hlg') {
@@ -496,6 +506,7 @@ function ShellVideo(options) {
496506
sid: null,
497507
};
498508
avgDuration = 0;
509+
durationReady = false;
499510
ipc.send('mpv-command', ['stop']);
500511
onPropChanged('loaded');
501512
onPropChanged('stream');

0 commit comments

Comments
 (0)