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

Audio not stoping in the player #2005

Closed
santoshgistto opened this issue Apr 10, 2023 · 20 comments · Fixed by #2147
Closed

Audio not stoping in the player #2005

santoshgistto opened this issue Apr 10, 2023 · 20 comments · Fixed by #2147
Assignees
Labels
bug Something isn't working

Comments

@santoshgistto
Copy link

Looks like audio not stopping when we go to another tab in the browser
Steps:

  1. play video here https://remotion-poc.vercel.app/
  2. Go to next tab or open the tab
@santoshgistto santoshgistto added the bug Something isn't working label Apr 10, 2023
@JonnyBurger
Copy link
Member

I can confirm the bug. Thanks for filing and hope to find a fix it!

@CruuzAzul
Copy link
Contributor

CruuzAzul commented Apr 10, 2023

I can take this bug 🥳 I think we can even make the whole player pause when we change tabs wyt ?
I'll make a first PR to do this and we'll see if it's the behaviour we want 😊

@JonnyBurger
Copy link
Member

Would be very happy if you investigated this @CruuzAzul!

Seems like Chrome is pausing requestAnimationFrame() when the tab is not focused.
Pausing the entire video is also a nice feature, but if we can avoid it, we should first focus on this bug specifically.

@CruuzAzul
Copy link
Contributor

CruuzAzul commented Apr 10, 2023

We should be able to do something in the player package using the visibilitychange event listener, I think this is usually the event that is used to deal with these tab change problems ! When listening to this event we should be able to either pause the player or mute it 😊

I'll take a look at this 😉

@JonnyBurger
Copy link
Member

Just to clear up any confusion: The bug is not about pausing the whole video!

The bug is that when the website is visited, the video starts playing, and when you tab to another site, then the audio keeps playing, even when the Remotion video finishes!

So to pause the whole video would only be a workaround if there is no better way to ensure the audio finishes if the audio finishes.

@CruuzAzul
Copy link
Contributor

Oh ok i see, i hadn't understood the problem like that, indeed thanks for the clarification ! 😅 I'll look into it 😊

@santoshgistto
Copy link
Author

I can confirm the bug. Thanks for filing and hope to find a fix it!

Thanks for making this awesome package

@santoshgistto
Copy link
Author

@JonnyBurger another behavior its not updating the audio also
please check the above url i have updated the sample app

@CruuzAzul
Copy link
Contributor

Is this related to the same thing ?

@santoshgistto
Copy link
Author

mostly audio is not getting replaced

@santoshgistto
Copy link
Author

@CruuzAzul you reproduce here https://remotion-poc.vercel.app/

@CruuzAzul
Copy link
Contributor

@santoshgistto yes thanks ! I wanted to know if this problem was related to the first problem that appears when changing tabs in the browser 🤔

@CruuzAzul
Copy link
Contributor

@JonnyBurger for the first issue by searching on the documentation it seems that is a feature of setAnimationFrame at work... Most of the solutions people propose to avoid the kind of problem we have seem to be to use the visibilityChange, I don't know if anyone has another idea

requestAnimationFrame() calls are paused in most browsers when running in background tabs or hidden <iframe>s in order to improve performance and battery life.
https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame

@santoshgistto
Copy link
Author

@santoshgistto
Copy link
Author

@santoshgistto yes thanks ! I wanted to know if this problem was related to the first problem that appears when changing tabs in the browser 🤔

i believe its related to each other

@JonnyBurger
Copy link
Member

Those are two different bugs. The second one I moved to #2033

@santoshgistto
Copy link
Author

Thanks @JonnyBurger

@JonnyBurger
Copy link
Member

@CruuzAzul The visibilitychange thing seems also like it is the way to go.
I'm not sure how to proceed once we figure out that the tab is in the background.

Do we switch to setTimeout()? Do we calculate when to stop the audio?
If this is all funky and we cannot rely on the browser to reliably end the audio, then maybe we should make a setting to stop the video entirely and document this behavior.

@CruuzAzul
Copy link
Contributor

@JonnyBurger I don't know... can we really have cases where we want the video to keep running in the background when we change tabs ? Maybe it makes sense to stop the video on the player when you switch tabs rather than calculating the time left on the audio and stopping it manually 🤔

@JonnyBurger
Copy link
Member

@CruuzAzul I do think it makes sense to keep the audio running in the background yes!
This is also the behavior on YouTube for example.

I am going to make a PR myself if you don't mind where I will test to use setTimeout() instead of requestAnimationFrame in the background and see if that fixes it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants