Question

How to play audio tracks continuously from a web app on IOS when phone locked?

  • 13 November 2019
  • 0 replies
  • 34 views

Visit Soundcloud and play any song using an iPhone (I have an iPhone 5s which I'm using it to test my web app.). If you lock the phone and the song finishes, the next track will start playing. This is something I'm trying to implement for my app.

based on the research I have done, apple doesn't allow HTML5 audios to start programmatically. It needs some sort of user interaction but the question is, how does Soundcloud do it?

My app at the moment uses the "onended()" HTML5 method to check if the current track is finished playing and then starts the next one. This works on android and desktop but not on ios.

here is the part of the code that plays the next track for my app:

this.audio.onended = () => {
this.index++;
this.audio.currentTime = 0;
axios.patch('/api/track/'+this.track.id,);

if(this.index <= (this.tracks.length - 1)){
this.track = this.tracks[this.index];
this.audio.src = this.tracks[this.index].url;
this.audio.play();
Event.$emit('setCurrentPlayingTrack', this.tracks[this.index]);
this.$store.commit('setPlayingTrack', this.tracks[this.index]);
}else{
console.log('playlist ended');
}

}

btw I'm using VueJs to build my app.


0 replies

Be the first to reply!

Reply