diff --git a/pages/API/create-inner-audio-context/create-inner-audio-context.uvue b/pages/API/create-inner-audio-context/create-inner-audio-context.uvue index 1217da8d69828bba218babb6b1130b6002a8efa2..93d272a5c01470b00fd4454ad014b2a01f21fbee 100644 --- a/pages/API/create-inner-audio-context/create-inner-audio-context.uvue +++ b/pages/API/create-inner-audio-context/create-inner-audio-context.uvue @@ -27,7 +27,7 @@ - + 格式/路径示例 @@ -87,24 +87,30 @@ this.isCanplay = true; // 当音频可以播放时,获取缓冲信息 this.buffered = this._audioContext!.buffered; - this.duration = this._audioContext!.duration || 0; + this.duration = this._audioContext!.duration }); }, onchanging() { this._isChanging = true; }, - onchange(e) { + onchange(e : UniSliderChangeEvent) { console.log(e, 'e'); - let pos = typeof e === "number" ? e : e.detail.value; + let pos = e.detail.value; this._audioContext!.seek(pos); this.onSeeking() this.onSeeked() this._isChanging = false; }, + onchangeValue(pos:number) { + this._audioContext!.seek(pos); + this.onSeeking() + this.onSeeked() + this._isChanging = false; + }, startTimeInput(e : InputEvent) { - let startTimeValue = Number(e.detail.value) + let startTimeValue = parseInt(e.detail.value) this._audioContext!.startTime = startTimeValue; - this.onchange(startTimeValue) + this.onchangeValue(startTimeValue) }, setAutoplay() { this._audioContext!.autoplay = !this._audioContext!.autoplay; @@ -125,7 +131,7 @@ this._audioContext!.play(); this.isPlayEnd = false; if (this._audioContext!.startTime > 0) { - this.onchange(this._audioContext!.startTime) + this.onchangeValue(this._audioContext!.startTime) } this._audioContext!.onPlay(() => { this.isPaused = false; @@ -158,7 +164,7 @@ this._audioContext!.onTimeUpdate(() => { // console.log('onTimeUpdate:音频播放进度更新事件,currentTime',this._audioContext!.currentTime); if (this._isChanging === true) { return; } - this.currentTime = this._audioContext!.currentTime || 0; + this.currentTime = this._audioContext!.currentTime ?? 0; console.log('currentTime', this.currentTime); if (this.currentTime > this.buffered) { console.log('缓冲不足'); diff --git a/pages/API/create-inner-audio-context/inner-audio-format.uvue b/pages/API/create-inner-audio-context/inner-audio-format.uvue index 85f1bd7845ff5e4c326f725511cfca53f00b3794..ffa14f57f84653d1b561c0acc5445f1b0f08d2fd 100644 --- a/pages/API/create-inner-audio-context/inner-audio-format.uvue +++ b/pages/API/create-inner-audio-context/inner-audio-format.uvue @@ -1,137 +1,145 @@ - - - - - + + + + + \ No newline at end of file diff --git a/pages/API/create-inner-audio-context/inner-audio-path.uvue b/pages/API/create-inner-audio-context/inner-audio-path.uvue index db4e20511a086485a2ba8efbcbe46fcb0a6ffb85..a35e426175a21fc3c76a24846c49c172aeff7a4e 100644 --- a/pages/API/create-inner-audio-context/inner-audio-path.uvue +++ b/pages/API/create-inner-audio-context/inner-audio-path.uvue @@ -29,7 +29,7 @@ description: '本地路径:/static方式', src: '/static/test-audio/ForElise.mp3' }, - { + { description: '本地路径:../static/', src: '../../../static/test-audio/ForElise.mp3' }, @@ -62,7 +62,7 @@ this._audioContext!.pause(); this.isPlaying = false; }, - play(audioUrl, index) { + play(audioUrl:string, index:number) { // console.log(index,audioUrl); if (this.isPlaying && this.playIndex == index) { this.pause(); @@ -81,7 +81,7 @@ }); this._audioContext!.onError((err) => { this.isPlaying = false; - console.log('err', err); + console.log('err', err); }); } }