apache / apache/cordova-plugin-media

Playing multiple files sequentially in background doesn't work in iOS

Open
#213 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
391
Forks
762
PR merge metrics
No merged PRs in 30d

Description

Hello,

I have an app that plays preview mp3's of a music album, i.e. song1, after that song2, ...

Since there's no playBatch() function in the Media object of this plugin, I did that by playing the next file after the last had finished playing. This works great on Android (even in background).

In iOS when I put the app in background (UIBackgroundModes is set correctly in Xcode), it tries to play the next file but fails with error 4.

Here's the log:

2019-01-12 16:52:59.931116+0100 MyApp[13620:2524776] Unable to play audio: (null)
2019-01-12 16:52:59.952107+0100 MyApp[13620:2524565] Error while playing file:
2019-01-12 16:52:59.952184+0100 MyApp[13620:2524565] {"message":"","code":4}

So it seems that the callback in Media.MEDIA_STOPPED doesn't get the needed data in the background, because this is the place where I start playing the next file. **But the remote path of the audio file is correctly passed into the Media object.** Maybe this isn't possible in iOS in the background at all? I recently noticed that the app is paused here completely, so background sync of user data doesn't seem to be possible neither.

Is there a way to accomplish what I want? Is there a way to have a playMultiple() or playBatch() function or is there another issue with my files?

Thanks in advance!

Bye

Contributor guide

Open the contributing guide

Research direction

Start by reproducing sequential remote-file playback on iOS with the app backgrounded and inspect the Media.MEDIA_STOPPED callback alongside the reported error code 4. Check how UIBackgroundModes affects this flow and determine whether reliable background playback is supported; document the confirmed behavior and a supported path forward if one exists.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, javascript
Domain
audio-video-rtc, mobile-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.