Igalia / wolvic

A fast and secure browser for standalone virtual-reality and augmented-reality headsets.
https://wolvic.org
Mozilla Public License 2.0
792 stars 99 forks source link

Media stream detached from window in some cases? #598

Open bkardell opened 1 year ago

bkardell commented 1 year ago

Configuration

Wolvic version: 1.3.3 Wolvic build ID: 83 Hardware: Quest 2

Steps to Reproduce

  1. Go to https://heyvr.io/game/trajectile-command, click begin... wait for the music to start
  2. Do one of the following:
    • Launch a private session. The audio from trajectile command keeps playing, that seems wrong.
    • Click the 'tabs' view, find the one with trajecile-command and use the (x) to close the window. The music keeps playing.

Current Behavior

For several (though, not all) once audio starts playing, if the user launches a private session or, from the tab thumbnails view, closes the tab actively playing the music (or otherwise manages to supplant it out of the shown windows) the music continues. In the case the window is closed, the only way to stop this is to reboot the browser. Observed this behavior on trajectile command, iron rails (several heyvr games, but not all), robot rally.

Expected Behavior

Any sense of "closing" the window should cease all work associated with it..

javifernandez commented 1 year ago

Alternate steps to reproduce the problem:

  1. Go to https://heyvr.io/game/trajectile-command, click begin... wait for the music to start
  2. Click the 'tabs' view, find the one with trajecile-command and use the (x) to close the window.
javifernandez commented 1 year ago

Alternate steps to reproduce the problem:

  1. Click on "+" to launch a new Wolvic window
  2. Go to https://heyvr.io/game/trajectile-command, click begin... wait for the music to start
  3. Close the window where the game is being run
svillar commented 1 year ago

So whenever you have multiple windows you should have multiple GeckoSession with their own media state. However Gecko does not handle that very well, and does pretty bad things, like pausing all the sessions when you pause one. That's a well known issue of Gecko in Android that is not being addressed yet upstream.

svillar commented 1 year ago

I'm setting priority to low because I doubt this will be ever fixed in Gecko. We should wait for the Chromium backend to fix it.

bkardell commented 1 year ago

I can't reproduce this issue in Firefox for Android, fwiw @svillar

HollowMan6 commented 11 months ago

I tried to investigate this a little bit, looks like the mediaSession in that tab session has no control over the music at all (either pause or stop). And anyway, after session is closed, everything should get recycled, so I will assume this is something related to Gecko's bug as well. Although I'm not sure why it works for Firefox on Android.

HollowMan6 commented 11 months ago

I also experienced similar bugs which I believe are caused by the same culprit in Gecko:

  1. Have a fresh start of Wolvic
  2. Navigate to https://open.spotify.com/
  3. Play music, then you will find that although it's playing, we don't hear any sound.
  4. Open a new Window and navigate to a YouTube video, and start playing the video.
  5. You finally find that we now have the sound for both YouTube and Spotify.

I tried to debug the Spotify page, and I see no js error there, I also tried to add a catching log at muteAudio here and never see it being called during the process. I also tried to check the Android debug log and saw no error as well.

https://github.com/Igalia/wolvic/blob/033f5bd9b89d16b5f57f93902701c90e38b8da21/app/src/common/gecko/com/igalia/wolvic/browser/api/impl/MediaSessionDelegateImpl.java#L137-L139

So it must be some kind of bug in Gecko, and I believe it's because Gecko has some bugs identifying the media and activating mediaSession in the current web session. I think Firefox for Android might have implemented some methods to mitigate this issue on their side, but I'm not exactly sure how.

HollowMan6 commented 11 months ago

Now I know what's going on here, looks like it's because of our patch to Gecko: https://github.com/Igalia/wolvic-gecko-patches/blob/main/gecko-116.0.3/0007-Fix-YouTube-media-stopping-when-closing-a-window.patch

This issue seems to be a side effect of that patch, and we still have YouTube media stopped when closing a window even in Gecko 120 nightly

And we still have the error for Spotify despite the patch we already have.

javifernandez commented 11 months ago

Now I know what's going on here, looks like it's because of our patch to Gecko: https://github.com/Igalia/wolvic-gecko-patches/blob/main/gecko-116.0.3/0007-Fix-YouTube-media-stopping-when-closing-a-window.patch

This issue seems to be a side effect of that patch, and we still have YouTube media stopped when closing a window even in Gecko 120 nightly

And we still have the error for Spotify despite the patch we already have.

Do you mean that the patch causes the regression described in this issue and that it even doesn't fix the problems with YouTube ?

HollowMan6 commented 11 months ago

Do you mean that the patch causes the regression described in this issue

Yes.

that it even doesn't fix the problems with YouTube ?

Actually, I don't think that is a root fix, just a workaround. Since I can reproduce the YouTube media stops issue when closing a window even in Gecko 120 nightly without that patch, and YouTube works fine after I apply that patch, the patch does mitigate the YouTube issue.