Skip to content

Commit d9da700

Browse files
committed
HLS videos sometimes fail to reach "ended" state & cannot be restarted
https://bugs.webkit.org/show_bug.cgi?id=251119 rdar://102114139 Reviewed by Eric Carlson. When WebKit receives the AVPlayerItemDidPlayToEndTimeNotification notification, it still attempts to estimate the current time because it believes it is still playing, as it hasn't yet received the -timeControlStatus KVO. Reset the values for currentTime estimation when receiving this notification so that the values returned are consistent. * LayoutTests/http/tests/media/hls/hls-ended-expected.txt: Added. * LayoutTests/http/tests/media/hls/hls-ended.html: Added. * Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::didEnd): * Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::didEnd): Canonical link: https://commits.webkit.org/259342@main
1 parent 58e8ab3 commit d9da700

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
RUN(video.src = "../resources/hls/test-vod.m3u8")
3+
EVENT(canplay)
4+
RUN(video.currentTime = video.duration - 0.5)
5+
EVENT(seeked)
6+
RUN(video.play())
7+
EVENT(ended)
8+
END OF TEST
9+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>hls-ended</title>
5+
<script src=../../media-resources/video-test.js></script>
6+
<script>
7+
window.addEventListener('load', async event => {
8+
video = document.getElementById('video');
9+
run('video.src = "../resources/hls/test-vod.m3u8"');
10+
await waitFor(video, 'canplay');
11+
run('video.currentTime = video.duration - 0.5');
12+
await waitFor(video, 'seeked');
13+
run('video.play()');
14+
await waitFor(video, 'ended');
15+
endTest();
16+
});
17+
</script>
18+
</head>
19+
<body>
20+
<video id="video"></video>
21+
</body>
22+
</html>

Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ void MediaPlayerPrivateAVFoundation::didEnd()
687687
// Hang onto the current time and use it as duration from now on since we are definitely at
688688
// the end of the movie. Do this because the initial duration is sometimes an estimate.
689689
MediaTime now = currentMediaTime();
690+
ALWAYS_LOG(LOGIDENTIFIER, "currentTime: ", now, ", seeking: ", m_seeking);
690691
if (now > MediaTime::zeroTime() && !m_seeking)
691692
m_cachedDuration = now;
692693

Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,8 @@ static URL conformFragmentIdentifierForURL(const URL& url)
13881388
void MediaPlayerPrivateAVFoundationObjC::didEnd()
13891389
{
13901390
m_requestedPlaying = false;
1391+
m_timeControlStatusAtCachedCurrentTime = AVPlayerTimeControlStatusPaused;
1392+
m_wallClockAtCachedCurrentTime = std::nullopt;
13911393
MediaPlayerPrivateAVFoundation::didEnd();
13921394
}
13931395

0 commit comments

Comments
 (0)