arielfaur / ionic-audio

An audio player for Ionic 3 and Angular 4. Works with HTML 5 audio or native audio using Cordova Media plugin.
http://arielfaur.github.io/ionic-audio/2.0/index.html
MIT License
321 stars 163 forks source link

onFinish called while playing #212

Open SimoneMSR opened 5 years ago

SimoneMSR commented 5 years ago

I use the onFinish output to update my view, and show a play/stop icon near the progress bar.

The problem is that the onFinish event is fired while the audio is still playing, and not when it's completed.

Here's my HTML code

<img [src]=" (!song.track || !song.isPlaying) ? 'a.svg' : 'b.svg'">
<audio-track #providerTrack *ngIf="song.track != undefined " (onFinish)="songFinished($event)" [track]="song.track" >
     <audio-track-progress-bar dark duration progress [audioTrack]="providerTrack" [ngStyle]="{display: providerTrack.completed > 0 ? 'flex' : 'none'}">
     </audio-track-progress-bar>
</audio-track>

Here's my ts code

  songFinished(track){
    var song = this.songs.find(s => s.track && s.track.id == track.id);
    if(song && song.isPlaying){
      setTimeout(()=>{
        song.isPlaying=false;
        this.change.markForCheck();
      })
    }
  }