How to implement Background Mode for Cordova Media Plugin Playlist on IOS

I have successfully implement a playlist feature for a Cordova Media plugin (https://github.com/apache/cordova-plugin-media) in my application .

However, on IOS, once the app screen is locked the current playlist item completes but it won’t move on to the next item .

I tried to use the cordova-plugin-background-mode but this didn’t solve my problem or I don’t know how to make it solve my issue.
Below is my code


ionViewDidLoad(){
    this.backgroundMode.enable();
  }
PlayAllList(i, tracks: AudioFile[],surah) {
   
    var self = this;
  
    let fileDir = "";
    if(this.plt.is('android')){
      fileDir = this.file.externalDataDirectory
     }
     else{
       fileDir = this.file.documentsDirectory.substr(7)
     }
    this.Audiofile = this.media.create(fileDir + tracks[i].trackUrl);
   
    this.Audiofile.play({playAudioWhenScreenIsLocked:true})
   
    this.Audiofile.onSuccess.subscribe(() => {
      if ((i + 1) == tracks.length) {
       this.Notplaying = true;
        this.Audiofile.release(); 
      this.Audiofile = undefined;
  
      } else {
       
      
        this.Audiofile.release()
      
        self.PlayAllList(i + 1, tracks,surah)
      }

    })
  
  }

While things appears to work well on IOS. I got Background task expired while holding WebKit ProcessAssertion (isMainThread? 1). in IOS 13

I have been on this for days. any suggestion will be appreciated

You need to add in your AndroidXml…

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

I hope the help!

:slight_smile:

Thanks man. But I don’t have any issue with Android.