点击 stop 停止播并清除 setInterval ,但是 clearinterval 之后控制台仍然运行?
play() {
if (this.data.isSubscribe && this.data.classify != 'Audition') {
const content = '该课程仅对订阅用户开放';
app.show.modal({ content }, (res) => {
if (res.confirm) { }
})
} else {
clearInterval(this.data.exercise_timer);
clearInterval(this.data.audio_timer);
const file = this.data.curExercise.audio.file;
innerAudioContext.src = file;
innerAudioContext.onPlay(() => {
let duration = Math.floor(innerAudioContext.duration) * 1000;
console.log('播放中 => ', duration);
this.setData({
audio_status: '结束'
});
this._timer();
this.data.audio_timer = setInterval(() => {
if (this.data.audio_status === '播放') return;
innerAudioContext.seek(0);
console.log("audio_timer / 104 => ", this.data.audio_timer);
}, duration);
});
innerAudioContext.play();
}
},
stop() {
clearInterval(this.data.exercise_timer);
clearInterval(this.data.audio_timer);
innerAudioContext.onStop(() => {
console.log('播放结束');
this.setData({
audio_status: '播放'
});
this._accuracyCount();
});
innerAudioContext.stop();
console.log("audio_timer / 122 => ", this.data.audio_timer);
},
_timer() {
this.pureData.minute = 0;
this.pureData.second = 0;
this.pureData.millisecond = 0;
this.data.exercise_timer = setInterval(() => {
if (this.data.audio_status === '播放') return;
this._timerCount();
}, 50);
},
_timerCount() {
this.pureData.millisecond = this.pureData.millisecond + 5;
if (this.pureData.millisecond >= 100) {
this.pureData.millisecond = 0;
this.pureData.second = this.pureData.second + 1
};
if (this.pureData.second >= 60) {
this.pureData.second = 0;
this.pureData.minute = this.pureData.minute + 1
};
let second = (this.pureData.second <= 9) ? this.pureData.second.toString().padStart(2, '0') : this.pureData.second;
let minute = (this.pureData.minute <= 9) ? this.pureData.minute.toString().padStart(2, '0') : this.pureData.second;
this.setData({
time_count: `${minute}:${second}`
});
console.log("time_count => ", this.data.time_count);
},
已解决
this.data.exercise_timer = setInterval(() => {
if (this.data.audio_status === '播放') return;
this._timerCount();
}, 50); (50改成100)
this.pureData.millisecond = this.pureData.millisecond + 5;
(5改成100)