Commit d0cb470b authored by liujiangnan's avatar liujiangnan

feat

parent cdcd8a1b
......@@ -526,31 +526,58 @@ new Vue({
if (this.currentPlayingRegion) {
this.stopCurrentPlayback();
}
this.wavesurfer.playPause();
this.isPlaying = !this.isPlaying;
// 添加:如果停止播放,强制重绘
if (!this.isPlaying) {
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
});
}
// 如果是锁定状态下的播放,需要在结束位置停止
if (this.isPageLocked && this.isPlaying) {
const remainingTime = (this.lockedPageEnd - this.wavesurfer.getCurrentTime()) * 1000;
this.playTimer = setTimeout(() => {
if (this.isPlaying) {
this.wavesurfer.pause();
this.isPlaying = false;
// 添加:播放结束后强制重绘
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
});
// 如果有选中的组,使用区间播放
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());
}
}, remainingTime);
// 开始播放
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.isPlaying = !this.isPlaying;
// 如果是锁定状态下的播放,需要在结束位置停止
if (this.isPageLocked && this.isPlaying) {
const remainingTime = (this.lockedPageEnd - this.wavesurfer.getCurrentTime()) * 1000;
this.playTimer = setTimeout(() => {
if (this.isPlaying) {
this.wavesurfer.pause();
this.isPlaying = false;
// 播放结束后强制重绘
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
});
}
}, remainingTime);
}
}
// 播放时保存当前位置作为缩放锚点
......@@ -1394,6 +1421,12 @@ new Vue({
// 直接选中组,不需要取消选中功能
this.selectedGroup = 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);
......@@ -1715,19 +1748,68 @@ new Vue({
this.wavesurfer.seekTo(this.lockedPageStart / this.wavesurfer.getDuration());
}
}
// 切换播放/暂停状态
this.wavesurfer.playPause();
this.isPlaying = !this.isPlaying;
// 如果正在区间播放,先清理
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.isPlaying = !this.isPlaying;
// 如果是锁定状态下的播放,需要在结束位置停止
if (this.isPageLocked && this.isPlaying) {
const remainingTime = (this.lockedPageEnd - this.wavesurfer.getCurrentTime()) * 1000;
this.playTimer = setTimeout(() => {
if (this.isPlaying) {
this.wavesurfer.pause();
this.isPlaying = false;
// 播放结束后强制重绘
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
});
}
}, remainingTime);
}
}
// 如果开始播放,保存当前位置作为缩放锚点
if (this.isPlaying) {
this.currentProgress = this.wavesurfer.getCurrentTime() / this.wavesurfer.getDuration();
} else {
// 如果停止播放,强制重绘
requestAnimationFrame(() => {
this.wavesurfer.drawBuffer();
});
}
}
},
......
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