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

useMediaControls: Unable to catch error event #494

Closed
cawa-93 opened this issue May 11, 2021 · 2 comments · Fixed by #509
Closed

useMediaControls: Unable to catch error event #494

cawa-93 opened this issue May 11, 2021 · 2 comments · Fixed by #509

Comments

@cawa-93
Copy link
Member

cawa-93 commented May 11, 2021

// Add new sources
sources.forEach(({ src, type }) => {
const source = document.createElement('source')
source.setAttribute('src', src)
source.setAttribute('type', type || '')
el.appendChild(source)
})

If you use an unavailable source, the browser will throw an error event. But not on the <video> tag, but on one of the <source> tags (This behavior may be different between browsers, I did not conduct a thorough study). It is important to keep track of such errors. But because the '` elements are inserted implicitly outside the template, there is no easy way to add listener events to them.

The only workaround I've found is to insert <source> tags into the template explicitly, and not pass src param to useMediaControls.

@wheatjs
Copy link
Member

wheatjs commented May 11, 2021

Hmm, that's a good point. Maybe we can return something like const { onSourceError } = useMediaControls() that would fire whenever there is an error. I don't quite remember how to create functions like that but I know it is possible.

Perhaps you have another idea on how we could handle it though?

@wheatjs
Copy link
Member

wheatjs commented May 11, 2021

Of course we could also just introduce it as a config option. Not sure which option would be preferable tbh

useMediaControls(video, {
  onSourceError(e) {
  
  }
})

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 a pull request may close this issue.

2 participants