fix(html5 audio): can't obtain the duration in some browser #1611
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.
Issue
When use html5 mode, in some browser, the duration can't be obtained while firing the canplaythrough event.
In the case, the code would end the sound instantly since the seek(0) is at the end(duration = 0). And the song would not be play due to the logic. We should try to obtain the duration.
Related Issues
Could check
ISSUE1: Xiaomi's browser can't play
in the linkhttps://qdmana.com/2021/06/20210622025155137h.html
Solution
The duration could be obtained once play the song. We can play it in muted and try to obtain the duration a few times.
Stop the play and seek to 0 once obtained the duration.
In my test, the duration could be obtained within 10 ms. The user is completely unaware it.
Reproduction/Testing
Play the any song in browser build-in XiaoMI note 3. But it's not easy to get the real device.
We can set the duration to 0 in _loadListener function, it could be testing as well.
Breaking Changes
None