Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(html5 audio): can't obtain the duration in some browser #1611

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

foamzou
Copy link

@foamzou foamzou commented Jul 31, 2022

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.

// End the sound instantly if seek is at the end.
if (seek >= stop) {
  self._ended(sound);
  return;
}

Related Issues

Could check ISSUE1: Xiaomi's browser can't play in the link
https://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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant