canalplus / rx-player

DASH/Smooth HTML5 Video Player
https://developers.canal-plus.com/rx-player/
Apache License 2.0
860 stars 131 forks source link

Fix MULTI_THREAD timing issue on Samsung TV #1556

Closed peaBerberian closed 1 week ago

peaBerberian commented 1 week ago

We recently noticed an issue when loading multiple contents that led to infinite loading, that was only seen on Samsung TVs.

After investigation, we noticed that there's a small window of time where the messages sent by the WebWorker are not listened by the main thread, that lead to those infinite loading as the main thread is still waiting for a message the Worker already sent.

This happened if the message was sent by the worker during the short time interval between:

Basically, this time interval should roughly be equal to the time it takes to "stop" the previous content (which we do by emptying the HTMLMediaElement's src attribute), so a really short time yet still too long to possibly lead to issue (if for example the MPD loads faster than the stop operation, the main thread wouldn't get the info).

There's multiple ways we could fix the issue. For now, I chose to add a way I'm not perfectly happy with due to the amount of logic added but which should work:

I tested it with success on a Samsung TV reproducing the issue.