I have a been facing a rather awkward bug from my Ionic angular project for android. I have an audio player with a range element, when I evoke (touchend) event handler, I wish to assign a value of the x point (in seconds) from the range that the user picked. When I assign the value to currentTime property of my Audio object, currentTime property value changes to 0.
player.ts
@ViewChild("range", { static: false }) range: IonRange;
progress = 0;
isPlaying = false;
isTouched = false;
currSecText;
durationText;
duration = 0;
currRangeTime;
currRangeValue;
currSong: HTMLAudioElement;
.....
.....
touchEnd(event) {
this.isTouched = false;
this.currSong.currentTime = Number(event.changedTouches[0].screenX)
this.timeUpdate();
if(this.isPlaying) {
this.currSong.play()
}
}
timeUpdate() {
try {
this.currSong.addEventListener("timeupdate", () => {
if(!this.isTouched) {
this.currRangeTime = Number(this.currSong.currentTime.toFixed(2).toString().substring(0, 5));
this.currSecText = this.sToTimeInSec(this.currSong.currentTime);
this.progress = (Math.floor(this.currSong.currentTime) / Math.floor(this.currSong.duration));
if (this.currSong.currentTime == this.currSong.duration && this.repeat === 'noRepeat') {
this.playNext();
} else if (this.currSong.currentTime == this.currSong.duration && this.repeat === 'repeatOne') {
var index = this.songs.findIndex(x => x.title == this.currTitle);
this.playSong(this.songs[index]);
}
}
});
} catch (error) {
console.log(error)
}
}
**player.html**
<ion-range #range (touchmove)="touchMove($event)" (touchend)="touchEnd($event)" (touchstart)="touchStart()"
max="{{maxRangeValue}}" [(ngModel)]="currRangeTime" color=warning>