ionic-audio icon indicating copy to clipboard operation
ionic-audio copied to clipboard

Question: How to pause/stop currently playing track when new track is played? (v2)

Open tjohnson5 opened this issue 9 years ago • 5 comments

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 avatar Aug 02 '16 18:08 tjohnson5

@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:

arielfaur avatar Aug 11 '16 13:08 arielfaur

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 :)

tjohnson5 avatar Aug 11 '16 16:08 tjohnson5

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

tbergeron avatar May 30 '17 16:05 tbergeron

TODO

arielfaur avatar Jun 02 '17 20:06 arielfaur

same issue

ghost avatar Jun 09 '18 09:06 ghost