Question: How to pause/stop currently playing track when new track is played? (v2)
Hello!
I've been messing with this for some time and haven't found a proper solution yet (I'm somewhat new to this and figured someone else may benefit from the question).
I'm currently using v2 "playlist" in my app. Currently. I can play several tracks all at the same time. I would like for the current track that is playing to stop/pause when a new track is played. Could someone point me in the right direction here?
Thanks!
@tjohnson5 At the moment there is a way to catch the onFinish event when playback has finished, but currently there isn't a way to determine when a new track is played. However I see now that this is needed for your use case and possibly others' too. I will look into it :smile:
Thanks that'd be awesome!
As a temporary solution, I just basically took your template behind audio-track-play and the play/pause "toggle" method and dropped it straight into my page and controller.
<button clear (click)="toggle(i)" [disabled]="audio.error || audio.isLoading"> <ion-icon name="pause" *ngIf="audio.isPlaying && !audio.isLoading"></ion-icon> <ion-icon name="play" *ngIf="!audio.isPlaying && !audio.isLoading"></ion-icon> <ion-spinner *ngIf="audio.isLoading && !audio.error"></ion-spinner> </button>
Toggle method in my controller:
toggle(index) { if (this._audioProvider.tracks[index].isPlaying) { this._audioProvider.pause(index); } else { this._audioProvider.pause(); // Pause all others this._audioProvider.play(index); }
Then of course I'd have to apply some styling to that button, but seems to work fine for now :)
Inactive issue? Can we close this?
Otherwise you can review these: https://github.com/arielfaur/ionic-audio/issues/88 https://github.com/arielfaur/ionic-audio/issues/114 https://github.com/arielfaur/ionic-audio/issues/122
TODO
same issue