Commit d0cb470b authored by liujiangnan's avatar liujiangnan

feat

parent cdcd8a1b
...@@ -527,15 +527,41 @@ new Vue({ ...@@ -527,15 +527,41 @@ new Vue({
this.stopCurrentPlayback(); this.stopCurrentPlayback();
} }
this.wavesurfer.playPause(); // 如果有选中的组,使用区间播放
this.isPlaying = !this.isPlaying; if (this.selectedGroup !== null && this.currentGroup) {
const regionId = `group-${this.selectedGroup}`;
const region = this.audioRegions[regionId];
if (region) {
// 获取当前时间,如果已经超过结束时间,则重新定位到开始时间
const currentTime = this.wavesurfer.getCurrentTime();
if (currentTime >= this.currentGroup.end) {
this.wavesurfer.seekTo(this.currentGroup.start / this.wavesurfer.getDuration());
}
// 开始播放
this.wavesurfer.play();
this.isPlaying = true;
this.currentPlayingRegion = regionId;
// 添加:如果停止播放,强制重绘 // 设置定时器在结束时间停止
if (!this.isPlaying) { const remainingTime = (this.currentGroup.end - this.wavesurfer.getCurrentTime()) * 1000;
this.playTimer = setTimeout(() => {
if (this.isPlaying && this.currentPlayingRegion === regionId) {
this.wavesurfer.pause();
this.isPlaying = false;
this.currentPlayingRegion = null;
// 播放结束后强制重绘
requestAnimationFrame(() => { requestAnimationFrame(() => {
this.wavesurfer.drawBuffer(); this.wavesurfer.drawBuffer();
}); });
} }
}, remainingTime);
}
} else {
// 没有选中组,正常播放
this.wavesurfer.playPause();
this.isPlaying = !this.isPlaying;
// 如果是锁定状态下的播放,需要在结束位置停止 // 如果是锁定状态下的播放,需要在结束位置停止
if (this.isPageLocked && this.isPlaying) { if (this.isPageLocked && this.isPlaying) {
...@@ -545,13 +571,14 @@ new Vue({ ...@@ -545,13 +571,14 @@ new Vue({
this.wavesurfer.pause(); this.wavesurfer.pause();
this.isPlaying = false; this.isPlaying = false;
// 添加:播放结束后强制重绘 // 播放结束后强制重绘
requestAnimationFrame(() => { requestAnimationFrame(() => {
this.wavesurfer.drawBuffer(); this.wavesurfer.drawBuffer();
}); });
} }
}, remainingTime); }, remainingTime);
} }
}
// 播放时保存当前位置作为缩放锚点 // 播放时保存当前位置作为缩放锚点
if (this.isPlaying) { if (this.isPlaying) {
...@@ -1394,6 +1421,12 @@ new Vue({ ...@@ -1394,6 +1421,12 @@ new Vue({
// 直接选中组,不需要取消选中功能 // 直接选中组,不需要取消选中功能
this.selectedGroup = groupIndex; this.selectedGroup = groupIndex;
this.currentGroup = this.currentPage.groups[groupIndex]; this.currentGroup = this.currentPage.groups[groupIndex];
// 只定位到组的开始时间,不自动播放
const duration = this.wavesurfer.getDuration();
if (duration && this.currentGroup.start !== undefined) {
this.wavesurfer.seekTo(this.currentGroup.start / duration);
}
}; };
region.element.removeEventListener('click', handleClick); region.element.removeEventListener('click', handleClick);
...@@ -1716,19 +1749,68 @@ new Vue({ ...@@ -1716,19 +1749,68 @@ new Vue({
} }
} }
// 切换播放/暂停状态 // 如果正在区间播放,先清理
if (this.currentPlayingRegion) {
this.stopCurrentPlayback();
}
// 如果有选中的组,使用区间播放
if (this.selectedGroup !== null && this.currentGroup) {
const regionId = `group-${this.selectedGroup}`;
const region = this.audioRegions[regionId];
if (region) {
// 获取当前时间,如果已经超过结束时间,则重新定位到开始时间
const currentTime = this.wavesurfer.getCurrentTime();
if (currentTime >= this.currentGroup.end) {
this.wavesurfer.seekTo(this.currentGroup.start / this.wavesurfer.getDuration());
}
// 开始播放
this.wavesurfer.play();
this.isPlaying = true;
this.currentPlayingRegion = regionId;
// 设置定时器在结束时间停止
const remainingTime = (this.currentGroup.end - this.wavesurfer.getCurrentTime()) * 1000;
this.playTimer = setTimeout(() => {
if (this.isPlaying && this.currentPlayingRegion === regionId) {
this.wavesurfer.pause();
this.isPlaying = false;
this.currentPlayingRegion = null;
// 播放结束后强制重绘
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
});
}
}, remainingTime);
}
} else {
// 没有选中组,正常播放
this.wavesurfer.playPause(); this.wavesurfer.playPause();
this.isPlaying = !this.isPlaying; this.isPlaying = !this.isPlaying;
// 如果开始播放,保存当前位置作为缩放锚点 // 如果是锁定状态下的播放,需要在结束位置停止
if (this.isPageLocked && this.isPlaying) {
const remainingTime = (this.lockedPageEnd - this.wavesurfer.getCurrentTime()) * 1000;
this.playTimer = setTimeout(() => {
if (this.isPlaying) { if (this.isPlaying) {
this.currentProgress = this.wavesurfer.getCurrentTime() / this.wavesurfer.getDuration(); this.wavesurfer.pause();
} else { this.isPlaying = false;
// 如果停止播放,强制重绘
// 播放结束后强制重绘
requestAnimationFrame(() => { requestAnimationFrame(() => {
this.wavesurfer.drawBuffer(); this.wavesurfer.drawBuffer();
}); });
} }
}, remainingTime);
}
}
// 如果开始播放,保存当前位置作为缩放锚点
if (this.isPlaying) {
this.currentProgress = this.wavesurfer.getCurrentTime() / this.wavesurfer.getDuration();
}
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment