goldfire / howler.js

Javascript audio library for the modern web.
https://howlerjs.com
MIT License
24.04k stars 2.24k forks source link

iOS Lock Screen - Should Audio still play? #966

Closed coretekk closed 4 years ago

coretekk commented 6 years ago

On my android device audio plays when the screen is locked.

Now I got a report that the audio stops playing when the screen is locked on iOS. Unfortunately I can't test it because I don't have an iOS device. Anyone knows if this is this by apple policy? Any work around?

new Howl({
            src: [track],
            html5: true,
            loop: false,
            preload: true,
            autoplay: false,
            onload: function() {
...
coretekk commented 6 years ago

If anyone else encounters this, here is more information: https://debuggerdotbreak.judahgabriel.com/2016/12/13/its-almost-2017-and-html5-audio-is-still-broken-on-ios/

cylkee commented 6 years ago

I tried the demo Music Player on this page https://howlerjs.com/ on an iPad Pro and it would not advance the playlist after the first track on the lock screen :(

aareeph commented 6 years ago

This is due to the Auto-play policy on iOS Safari. In Playlist another audio won't start automatically because it requires a user interaction.

I overcame this issue by playing a silent audio on loop with html5: true flag. This will keep the context alive for audios. Then you can play rest of the files in sequence with html5: false flag.

rlyttle commented 5 years ago

@aareeph could you possibly elaborate on your playing silent audio loop? Does this work on iOS and android?

I've tried what you suggested but it's had no effect. Example code would be really appreciated!

aareeph commented 5 years ago

Hi @rlyttle, actually the silent audio loop trick didn't work for me very well for iOS. Although I was able to play next audio without user interaction, this wasn't working fine when the app is in background or device is locked.

For Android everything worked fine and we don't need to do the silent audio loop trick at all.

Please have a look at these release notes. Author has updated the library to play next audios in a pool without any user interaction. So I believe that you don't need any workaround for now. https://github.com/goldfire/howler.js/blob/master/CHANGELOG.md#210-december-12-2018

rlyttle commented 5 years ago

@aareeph Thanks for the detailed response! I'll do some investigation!

goldfire commented 4 years ago

Closing due to inactivity. If this is still an issue, reply with more info and I'll reopen.