|
|
|
@ -15,10 +15,11 @@ Page({
@@ -15,10 +15,11 @@ Page({
|
|
|
|
|
url: 'http://m10.music.126.net/20241126110303/3f2481d2d6d50acd2009359539eadda0/ymusic/5353/0f0f/0358/d99739615f8e5153d77042092f07fd77.mp3', |
|
|
|
|
play: false, |
|
|
|
|
time: '00:00/00:00', |
|
|
|
|
currentTime: 0, |
|
|
|
|
drag: false, |
|
|
|
|
|
|
|
|
|
toastShow: false, |
|
|
|
|
toastType: 3, |
|
|
|
|
currentTime: 0, |
|
|
|
|
}, |
|
|
|
|
innerAudioContext: null as WechatMiniprogram.InnerAudioContext | null, |
|
|
|
|
onLoad(options) { |
|
|
|
@ -168,7 +169,7 @@ Page({
@@ -168,7 +169,7 @@ Page({
|
|
|
|
|
this.innerAudioContext.seek(currentTime); |
|
|
|
|
this.innerAudioContext.play(); |
|
|
|
|
const listener = () => { |
|
|
|
|
if (this.innerAudioContext) { |
|
|
|
|
if (this.innerAudioContext && !this.data.drag) { |
|
|
|
|
const { currentTime, duration } = this.innerAudioContext; |
|
|
|
|
const time = `${this.formatTime(currentTime)}/${this.formatTime(duration)}`; |
|
|
|
|
const progress = (currentTime / duration) * 100; |
|
|
|
@ -182,6 +183,7 @@ Page({
@@ -182,6 +183,7 @@ Page({
|
|
|
|
|
}; |
|
|
|
|
this.innerAudioContext.onTimeUpdate(listener); |
|
|
|
|
this.innerAudioContext.onEnded(() => { |
|
|
|
|
this.innerAudioContext?.seek(0); |
|
|
|
|
this.setData({ |
|
|
|
|
play: false, |
|
|
|
|
}); |
|
|
|
@ -201,12 +203,31 @@ Page({
@@ -201,12 +203,31 @@ Page({
|
|
|
|
|
handlePause() { |
|
|
|
|
if (this.innerAudioContext) { |
|
|
|
|
this.innerAudioContext.pause(); |
|
|
|
|
this.innerAudioContext.offTimeUpdate() |
|
|
|
|
this.innerAudioContext.offEnded() |
|
|
|
|
this.innerAudioContext.offPlay() |
|
|
|
|
this.innerAudioContext.offPause() |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
handleDragStart() { |
|
|
|
|
this.setData({ |
|
|
|
|
drag: true, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleDragEnd() { |
|
|
|
|
this.setData({ |
|
|
|
|
drag: false, |
|
|
|
|
}); |
|
|
|
|
if (this.data.play) { |
|
|
|
|
this.innerAudioContext?.seek(this.data.currentTime); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
handleDrag(e: any) { |
|
|
|
|
const current = e.detail.value; |
|
|
|
|
const duration = this.innerAudioContext?.duration || this.data.chapter.AudioUrl.duration; |
|
|
|
|
const currentTime = (current / 100) * duration; |
|
|
|
|
const time = `${this.formatTime(currentTime)}/${this.formatTime(duration)}`; |
|
|
|
|
this.setData({ |
|
|
|
|
time, |
|
|
|
|
currentTime, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
formatTime(time: number) { |
|
|
|
|
const minutes = Math.floor(time / 60); |
|
|
|
|
const seconds = Math.floor(time % 60); |
|
|
|
|