Return undefined
from getCurrentTime()
when it is unknown
#131
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📺 What
Currently
getCurrentTime()
has a default value of 0 in several cases. This is not ideal because it makes it impossible to know if it truly is time 0, or if the time is not known yet.It also sometimes returns the wrong value.
An example where this is an issue is if you start a live stream from the live point. Currently you will get back the incorrect time whilst the stream loads, and then it will jump to the correct value.
With this PR when the strategy is still loading (hasn't changed the state to something other than
WAITING
)getCurrentTime()
will now always returnsetCurrentTime
request orinitialPlaybackTime
orundefined
I chose to put this logic in 'bigscreenplayer.js' instead of the individual strategies because I think this is something that benefits them all.
This also means a call to
getCurrentTime()
in the same stack assetCurrentTime()
is guaranteed to be what you expect even if the update happens asynchronously in the strategy.This PR also contains a fix in the
msestrategy
getCurrentTime()
to prevent it returning incorrect values when the media element isn't ready. This change isn't strictly needed given the other change in 'bigscreenplayer.js' prevents it causing an issue, but it's probably good to fix anyway.🛠 How
SeekState
enum which can beNONE
,QUEUED
orIN_FLIGHT
. When a seek isQUEUED
orIN_FLIGHT
we now return the time we're seeking to fromgetCurrentTime()
instead of calling through to the strategy.msestrategy
returnundefined
instead of0
fromgetCurrentTime
when the time is unknown.msestrategy
returnundefined
when the media elementreadyState
is at leastHAVE_METADATA
. Before this dashjs has not set the current time to near the live point meaning it would return the wrong value.✅ Acceptance criteria
getCurrentTime()
returnsundefined
whilst a stream is loading with noinitialPlaybackTime
using the mse strategygetCurrentTime()
always returns the time it was set to immediately aftersetCurrentTime()
getCurrentTime()
initially returns the value ofinitialPlaybackTime
.getCurrentTime()
returns the expected time when the media state is notWAITING