fix: AudioPlayerComposable - Prevent loop in firefox #935
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.
Renamed branch, original PR: #929
closes #921
Currently the AudioPlayerComposable component has a problem with live streaming, where it infinitely loops the first second of audio if rendered in the Firefox browser. The component seems to work fine in Chrome. The reason it doesn't work in Firefox comes down to how the two browsers handle the onDurationChange event, or more specifically the value that is applied to
duration
for unbounded streams.In Chrome the browser assigns
duration
the value ofInfinity
, which is in accordance with the HTML spec (see also MDN), but in Firefox (for reasons I haven't been able to discover) the duration property is a continuously updated float.Since we tie this continuous update to our component's
duration
state and we have that sameduration
listed as a dependency in auseEffect
, this means that the callback for theuseEffect
is being continuously updated for unbounded streams in Firefox. That same callback is used to initialise the component by setting the current time to 0.This results in the infinite loop we are seeing where the audio's current time is constantly being reset as new audio data arrives and the value of
duration
changes.Since we only really appear to want to call this function initially or when the src of the audio changes, I am proposing that we resolve the issue by removing
duration
as a factor of the component's initial setup entirely.I have done:
I have tested manually: