Skip to content

Commit c68b56b

Browse files
committed
Fix functional test async play handling
1 parent e61d1f4 commit c68b56b

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

tests/functional/auto/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ body {
22
background-color: #cccccc;
33
}
44

5+
#video {
6+
width: 100%;
7+
}
8+
59
#log {
610
position: fixed;
711
top: 0;

tests/functional/auto/testbench.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,42 @@ function startStream(streamUrl, config, callback, autoplay) {
109109
);
110110
console.log('[test] > userAgent:', navigator.userAgent);
111111
if (autoplay !== false) {
112-
hls.on(Hls.Events.MANIFEST_PARSED, function () {
113-
console.log('[test] > Manifest parsed. Calling video.play()');
112+
// attempt to ready playback in case test start is treated as a user interaction
113+
video.src = null;
114+
video.load();
115+
116+
hls.on(Hls.Events.MEDIA_ATTACHED, function () {
117+
console.log('[test] > Media attached. Calling video.play()');
114118
var playPromise = video.play();
115119
if (playPromise) {
116-
playPromise.catch(function (error) {
117-
console.log(
118-
'[test] > video.play() failed with error: ' +
119-
error.name +
120-
' ' +
121-
error.message
122-
);
123-
if (error.name === 'NotAllowedError') {
124-
console.log('[test] > Attempting to play with video muted');
125-
video.muted = true;
126-
return video.play();
127-
}
128-
});
120+
playPromise
121+
.catch(function (error) {
122+
if (error.name === 'NotAllowedError') {
123+
console.log('[test] > Attempting to play with video muted');
124+
video.muted = true;
125+
return video.play();
126+
}
127+
throw error;
128+
})
129+
.then(function () {
130+
video.controls = true;
131+
console.log(
132+
'[test] > video.play() resolved' +
133+
(video.muted ? ' (muted)' : '') +
134+
' currentTime: ' +
135+
video.currentTime
136+
);
137+
})
138+
.catch(function (error) {
139+
console.log(
140+
'[test] > video.play()' +
141+
(video.muted ? ' (muted)' : '') +
142+
' failed with error: ' +
143+
error.name +
144+
' ' +
145+
error.message
146+
);
147+
});
129148
}
130149
});
131150
}

0 commit comments

Comments
 (0)