Closed gagansawhney closed 6 years ago
Having the same issue. My use case is to count the number of times a user played the whole track.
In the console I can see:
Playing track /assets/audio/ogg/test.ogg
Play ended
Finished playback Track finished {src: "/assets/audio/ogg/test.ogg", preload: "metadata", id: 0}
Second Play
Loading track /assets/audio/ogg/test.ogg Track finished {src: "/assets/audio/ogg/test.ogg", preload: "metadata", id: 0} Track finished {src: "/assets/audio/ogg/test.ogg", preload: "metadata", id: 0} Track finished {src: "/assets/audio/ogg/test.ogg", preload: "metadata", id: 0} Playing track /assets/audio/ogg/test.ogg
Play ended
Finished playback Track finished {src: "/assets/audio/ogg/test.ogg", preload: "metadata", id: 0}
Third Play
Loading track /assets/audio/ogg/test.ogg Track finished {src: "/assets/audio/ogg/test.ogg", preload: "metadata", id: 0} Track finished {src: "/assets/audio/ogg/test.ogg", preload: "metadata", id: 0} Track finished {src: "/assets/audio/ogg/test.ogg", preload: "metadata", id: 0} Playing track /assets/audio/ogg/test.ogg
I've managed to workaround the issue by:
onTrackFinished(track: any) { let true_finished : any = Object.assign({},this._audioProvider.tracks[this._audioProvider.current]) if (true_finished._isLoading || true_finished._hasLoaded) return ... }
@veyDer I can't get your example to work. Can you explain further what you did?
Thx in advance
This is the relevant part of my .ts file:
repetition_cnt: number = 3 my_is_playing = false
togglePlayingFlag() { this.my_is_playing = !this.my_is_playing } onTrackFinished(track: any) { let true_finished : any = Object.assign({},this._audioProvider.tracks[this._audioProvider.current]) if (true_finished._isLoading || true_finished._hasLoaded) return console.log('Track finished') if (!this.my_is_playing) return this.my_is_playing = false
this.repetition_cnt--
if (this.repetition_cnt == 0) {
// the track has been played 3 times, do your stuff...
}
}
and here's the relevant part of my .html file: `
` Hope that helps.
Thank you for your help @veyDer
I'm not quite there yet. I can make the file play x times. After that it seems that the onFinish event is being called whenever I push a button (play button, next button etc). It's like the event is being fired on any change.
Are you using the code from npm or did you pull something from here?
@betatools Are you still struggling with this?
It works as expected the first time the audio file plays. When pressing play again, the onFinish method is being called right away and multiple times. I “fixed” it by setting a timer that prevents the logic in the onFinish event to run in the first few seconds of a play.
Now I can set a counter that works and makes it possible for the user to repeat a file x times
So to answer your question - I am not currently struggling with it, but it seems the onFinish event is weird.
I hope that made any sense 🙂
I have uploaded a screenshot here to explain the use of the repeat functionality
Thanks, I will look into it!
@betatools I just pushed version 3.2.2
to npm which fixes this issue with the track end event being called multiple times. Can you give it a go and let me know? 😄
@arielfaur Sure. Thank you very much for fixing this. I’ll get back to you soon 🙂
I just want to confirm that 3.2.2 fixed this, for me. Thank you so much!
In v 3.2 trackend gets called multiple times. This was fine till v3.0