* 绑定播放器控制事件
()
| 989 | * 绑定播放器控制事件 |
| 990 | */ |
| 991 | bindPlayerControls() { |
| 992 | if ( |
| 993 | this.bindingFlags.playerControls || |
| 994 | !this.dom.playPauseBtn || |
| 995 | !this.dom.speedBtn || |
| 996 | !this.dom.progressBar || |
| 997 | !this.dom.audioPlayer || |
| 998 | !this.dom.loopToggleBtn |
| 999 | ) { |
| 1000 | return; |
| 1001 | } |
| 1002 | this.bindingFlags.playerControls = true; |
| 1003 | |
| 1004 | // 播放/暂停 |
| 1005 | on(this.dom.playPauseBtn, 'click', () => { |
| 1006 | if (this.dom.audioPlayer.paused) { |
| 1007 | this.dom.audioPlayer.play(); |
| 1008 | } else { |
| 1009 | this.dom.audioPlayer.pause(); |
| 1010 | } |
| 1011 | }); |
| 1012 | |
| 1013 | // 倍速 |
| 1014 | on(this.dom.speedBtn, 'click', () => { |
| 1015 | this.cyclePlaybackSpeed(); |
| 1016 | }); |
| 1017 | |
| 1018 | // 循环 |
| 1019 | on(this.dom.loopToggleBtn, 'click', () => { |
| 1020 | this.toggleLoopPlayback(); |
| 1021 | this.state.sentence = false; |
| 1022 | }); |
| 1023 | |
| 1024 | // 进度条 |
| 1025 | const seekByClientX = (clientX) => { |
| 1026 | if (!this.dom.audioPlayer.duration) return; |
| 1027 | const rect = this.dom.progressBar.getBoundingClientRect(); |
| 1028 | const percent = clamp((clientX - rect.left) / rect.width, 0, 1); |
| 1029 | this.dom.audioPlayer.currentTime = percent * this.dom.audioPlayer.duration; |
| 1030 | }; |
| 1031 | |
| 1032 | on(this.dom.progressBar, 'click', (event) => { |
| 1033 | seekByClientX(event.clientX); |
| 1034 | }); |
| 1035 | |
| 1036 | on( |
| 1037 | this.dom.progressBar, |
| 1038 | 'pointerdown', |
| 1039 | (event) => { |
| 1040 | this.state.isProgressDragging = true; |
| 1041 | addClass(this.dom.progressBar, 'dragging'); |
| 1042 | this.dom.progressBar.setPointerCapture(event.pointerId); |
| 1043 | seekByClientX(event.clientX); |
| 1044 | }, |
| 1045 | { passive: true } |
| 1046 | ); |
| 1047 | |
| 1048 | on( |
no test coverage detected