ruffle-rs / ruffle

A Flash Player emulator written in Rust
https://ruffle.rs
Other
15.58k stars 809 forks source link

Background playback #7289

Open HT-7 opened 2 years ago

HT-7 commented 2 years ago

When I switch to a different tab on Newgrounds, Ruffle suspends the flash elements, whereas the original flash kept playing in background. Please bring background playback to Ruffle. Thanks in advance.

n0samu commented 2 years ago

Unfortunately, this is not possible due to the restrictions of modern web browsers. Browsers suspend canvas/WebGL elements in the background automatically, and all Ruffle can do is try to cooperate with that.

mero09-99 commented 2 years ago

is this still open by accident?

n0samu commented 2 years ago

Well, I've noticed that the swf2js Flash emulator is able to keep playing background music of games while the execution is otherwise suspended. I think this could be cool feature for Ruffle in the future, if it's possible.

ActionWavele commented 1 year ago

Flash player and SWF2js make it work, so try using JS and Ruffle to do the same!

mlindner commented 1 year ago

Any update on this?

n0samu commented 1 year ago

We could probably offer a config option to disable Ruffle's auto-suspend functionality, with the big caveat that Ruffle is still subject to the browser's own auto-suspension as I explained before. So background audio could keep playing, but the game wouldn't otherwise continue running for the most part, which could have strange effects sometimes. I've also been told that a lot of multiplayer Flash games were coded to exchange data with the server at regular intervals, and no matter what we do, this is probably going to be broken for the foreseeable future.

mlindner commented 1 year ago

I think that config option would be sufficient. Would that also keep flash video animations playing as well? It wouldn't be good to have the audio and video desync.

n0samu commented 1 year ago

I think it would cause desync, unfortunately.

mlindner commented 1 year ago

There should be a workaround given that there's code that explicitly shuts off the video when it goes into the background. https://github.com/ruffle-rs/ruffle/blob/695c2ff9f57e8e04faf663c3fb805b7bccc892cf/web/packages/core/src/ruffle-player.ts#L435

For example browsers often have options to shut off the feature that causes the issue this code tries to "fix" against.

n0samu commented 1 year ago

I already explained that Ruffle pauses itself because otherwise the browser would try to pause it anyway, leading to desyncs and other problems. And I don't believe there are any browser settings to change this, and even if there were, it wouldn't be realistic to expect users to change them.