我的 Ionic angular 项目 android 中遇到了一个相当尴尬的错误。我有一个带有 range 元素的音频播放器,当我调用 (touchend) 事件处理程序时,我希望从用户选择的范围中分配 x 点的值(以秒为单位)。当我将值分配给我的 Audio 对象的 currentTime 属性时,currentTime 属性值更改为 0。
player.ts
if (strstr (strtolower ($ user-> username), strtolower (my word)))
player.html
@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)
}
}