maxence-charriere / lofimusic

Lofimusic.app is an installable Progressive web app (PWA) that lists and displays famous YouTube Lo-Fi radios.
MIT License
576 stars 78 forks source link

Music stops playing in background on iOS #19

Open stefandesu opened 3 years ago

stefandesu commented 3 years ago

I found your project yesterday and I love it! Unfortunately, the music stops playing as soon as you put the PWA in the background on iOS. The thing is that I once researched this particular issue and it seems like this is an iOS restriction/bug that prevents it, so there might be nothing you can do.

However, I also noticed that the same thing happens in Safari on iOS (i.e. not installed as a PWA). In theory, sites in Safari should be able to play music in the background, at least that was my conclusion from the research I've done one.

Might be something to look into.

maxence-charriere commented 3 years ago
the music stops playing as soon as you put the PWA in the background on iOS

Unfortunately, this is a limitation related to all web browsers on mobile. Even when pinned on the home screen, it is still Safari that is running it.

Also, it is a Youtube video in the background but since I wanted the content you be embedded in the UI, I deactivated the feature that launches the video in full screen so there is no in picture mode.

stefandesu commented 3 years ago

Unfortunately, this is a limitation related to all web browsers on mobile. Even when pinned on the home screen, it is still Safari that is running it.

Okay so I haven't researched the technical details about this, but it is definitely possible to play audio in the background through Safari on iOS. That's what I found out back then: You can play audio in the background in a browser tab in Safari (example: https://epidemicsound.com), but not inside a PWA that was added to the home screen (I don't have an example to show this behavior, but back then I tested it with a simple example I made myself).

I guess since you are using a YouTube video embed, it will stop playing as soon as it goes in the background. The same happens with YouTube videos playing through the YouTube website in Safari. So I guess there's no way around this. Too bad. 😕

maxence-charriere commented 3 years ago

Yeah, it is a bummer but it is a limitation but also, I was thinking of hacking something like put the video in in-picture mode when the app loses focus but Youtube is blocking that mode if you are not a premium user.