w3c / mediasession

Media Session API
https://w3c.github.io/mediasession/
Other
129 stars 29 forks source link

Use within a PWA context / Service Worker to replicate native audio apps? #232

Open voxpelli opened 5 years ago

voxpelli commented 5 years ago

If one wants to create a Progressive Web App that mimics Spotify or one of the many podcasts apps out there, then currently one needs to have ones app be a Single Page Application, as neither the Media Session API nor the Web Audio API is available in a worker, they all expects the web page context to stay alive.

There is an open issue about making the Web Audio API available to Workers: https://github.com/WebAudio/web-audio-api/issues/1098

And the Media Session API would be the natural UI for such a background playback.

In w3c/mediasession#48 support for the Web Audio API was added, which meant that as long as https://github.com/WebAudio/web-audio-api/issues/1098 was solved then the Media Session API would likely be available for any AudioContext created within a Service Worker (or other supported Worker)

However, as noted in w3c/audio-session-detach#10, the addition from w3c/mediasession#48 was dropped in w3c/mediasession#135 so currently either that direct support for AudioContext would need to be restored for the Media Session API to be a usable interface for interacting with audio playing in workers – or the Media Session API would have to define its own availability within either Service Workers specifically or Workers in general – else it will stay impossible to fully mimic a native audio app as a PWA.

Could it be that the removal was caused by the split of this spec into the Media Session API spec and the Audio Focus API spec (https://github.com/WICG/audio-focus)?

Been asking around on Twitter about this over time, here's link to some of those discussions:

mounirlamouri commented 5 years ago

Could it be that the removal was caused by the split of this spec into the Media Session API spec and the Audio Focus API spec (https://github.com/WICG/audio-focus)?

Correct.

NavyCoat commented 3 years ago

@voxpelli is this what you described here will make me able to play two audio streams simultaneously, like for example, Spotify and my podcast PWA?

voxpelli commented 3 years ago

@NavyCoat Not really, it’s about controlling the playback in the background without relying on a window being open to play it.

A desktop app like Spotify is able to continue play even after you have closed its window, but that is currently not possible for a PWA as it can only do playback from within its HTML page, not from within its background service worker.

rektide commented 2 years ago

Connecting this to some other issues about,

voxpelli commented 1 year ago

Linking this issue to https://github.com/whatwg/html/issues/8538 as well

youennf commented 1 year ago

Marking as enhancement for now.

chrisn commented 1 year ago

Background playback is definitely an interesting use case for my organization. We'd like to enable media playback that can continue across same-site navigations, and redesigning as a single-page application would be far too costly.

With various proposals being suggested here (service workers, iframes that carry state between navigations, MediaSession for UI, Web Audio support, etc), it seems to me it's worth looking at how to do this holistically.