Sorry for the late reply. My local build stops working on emulator and it took me some time to get it working on the phone. I've been able to capture a [profile](https://share.firefox.dev/4b5ASSd) and it seems Youtube clears the media element source when Fenix is minimized so even though the control sends the 'play' command to call `HTMLMediaElement.play()`, it cannot load the media source and fails. I think although the 'check browser in background and if the media is paused' approach would fix the Youtube issue, it will regress current background playback behavior on other websites like Tiktok, where the control continues to work regardless of background and playback states. I tried Tiktok in Chrome and it also supports this behavior. In the profile I noticed 'MediaControl' log shows a playback state `eStopped` which is not defined by the `MediaSession` API but is available in the [MediaSession.Feature](https://searchfox.org/firefox-main/rev/ad106dcbb4483fb34c1b144fa74eb32e885171ce/mobile/android/android-components/components/concept/engine/src/main/java/mozilla/components/concept/engine/mediasession/MediaSession.kt#70). Maybe it can be used in this case? Alastor, would you like to give some suggestions?
Bug 2017451 Comment 9 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
Sorry for the late reply. My local build stops working on emulator and it took me some time to get it working on the phone. I captured a [profile](https://share.firefox.dev/4b5ASSd) and it seems Youtube clears the media element source when Fenix is minimized so even though the control sends the 'play' command to call `HTMLMediaElement.play()`, it cannot load the media source and fails. I think although the 'check browser in background and if the media is paused' approach would fix the Youtube issue, it will regress current background playback behavior on other websites like Tiktok, where the control continues to work regardless of background and playback states. I tried Tiktok in Chrome and it also supports this behavior. In the profile I noticed 'MediaControl' log shows a playback state `eStopped` which is not defined by the `MediaSession` API but is available in the [MediaSession.Feature](https://searchfox.org/firefox-main/rev/ad106dcbb4483fb34c1b144fa74eb32e885171ce/mobile/android/android-components/components/concept/engine/src/main/java/mozilla/components/concept/engine/mediasession/MediaSession.kt#70). Maybe it can be used in this case? Alastor, would you like to give some suggestions?
Sorry for the late reply. My local build stops working on emulator and it took me some time to get it working on the phone. I captured a [profile](https://share.firefox.dev/4b5ASSd) and it seems Youtube clears the media element source when Fenix is minimized so even though the control sends the 'play' command to call `HTMLMediaElement.play()`, it cannot load the media source and fails. I think although the 'check browser in background and if the media is paused' approach fixes the Youtube issue, it will regress current background playback behavior on other websites like Tiktok, where the control continues to work regardless of background and playback states. I tried Tiktok in Chrome and it also supports this behavior. In the profile I noticed 'MediaControl' log shows a playback state `eStopped` which is not defined by the `MediaSession` API but is available in the [MediaSession.Feature](https://searchfox.org/firefox-main/rev/ad106dcbb4483fb34c1b144fa74eb32e885171ce/mobile/android/android-components/components/concept/engine/src/main/java/mozilla/components/concept/engine/mediasession/MediaSession.kt#70). Maybe it can be used in this case? Alastor, would you like to give some suggestions?