Browse Source

fix(AudioControls): 初始化音频索引时跳过导语音频

修改多处音频索引初始化逻辑,优先选择第一个非导语音频作为起始播放位置。在循环播放和自动播放场景下同样应用此逻辑,避免从导语开始播放
main
前端-胡立永 20 hours ago
parent
commit
67811d3d16
1 changed files with 50 additions and 20 deletions
  1. +50
    -20
      subPages/home/AudioControls.vue

+ 50
- 20
subPages/home/AudioControls.vue View File

@ -321,7 +321,10 @@ export default {
this.totalTime = cachedAudio.totalDuration || 0;
this.hasAudioData = true;
this.isAudioLoading = false;
this.currentAudioIndex = 0;
//
const firstNonLeadIndex = this.findFirstNonLeadAudio();
this.currentAudioIndex = firstNonLeadIndex >= 0 ? firstNonLeadIndex : 0;
this.currentTime = 0;
this.currentHighlightIndex = -1;
@ -612,7 +615,10 @@ export default {
//
this.currentPageAudios = this.audioCache[cacheKey].audios;
this.totalTime = this.audioCache[cacheKey].totalDuration;
this.currentAudioIndex = 0;
//
const firstNonLeadIndex = this.findFirstNonLeadAudio();
this.currentAudioIndex = firstNonLeadIndex >= 0 ? firstNonLeadIndex : 0;
this.isPlaying = false;
this.currentTime = 0;
this.hasAudioData = true;
@ -743,7 +749,10 @@ export default {
if (!firstAudioPlayed && this.currentPageAudios.length > 0) {
firstAudioPlayed = true;
this.hasAudioData = true;
this.currentAudioIndex = 0;
//
const firstNonLeadIndex = this.findFirstNonLeadAudio();
this.currentAudioIndex = firstNonLeadIndex >= 0 ? firstNonLeadIndex : 0;
@ -1784,16 +1793,23 @@ export default {
console.log('🎵 handlePlaybackComplete: 所有音频播放完毕');
if (this.isLoop) {
//
console.log('🎵 handlePlaybackComplete: 循环播放,重置索引为0');
this.currentAudioIndex = 0;
// -
console.log('🎵 handlePlaybackComplete: 循环播放,查找第一个非导语音频');
const firstNonLeadIndex = this.findFirstNonLeadAudio();
//
const firstAudio = this.currentPageAudios[0];
if (firstAudio && firstAudio.url) {
this.playAudio();
if (firstNonLeadIndex >= 0 && firstNonLeadIndex < this.currentPageAudios.length) {
this.currentAudioIndex = firstNonLeadIndex;
const firstAudio = this.currentPageAudios[firstNonLeadIndex];
if (firstAudio && firstAudio.url) {
console.log(`🎵 handlePlaybackComplete: 循环播放从非导语音频开始,索引=${firstNonLeadIndex}, isLead=${firstAudio.isLead}`);
this.playAudio();
} else {
console.error('🎵 handlePlaybackComplete: 第一个非导语音频数据无效,停止循环播放');
this.stopPlayback();
}
} else {
console.error('🎵 handlePlaybackComplete: 第一个音频数据无效,停止循环播放');
console.error('🎵 handlePlaybackComplete: 找不到有效的非导语音频,停止循环播放');
this.stopPlayback();
}
} else {
@ -2811,11 +2827,14 @@ export default {
this.currentPageAudios = cachedData.audios;
this.totalDuration = cachedData.totalDuration;
//
this.currentAudioIndex = 0;
//
const firstNonLeadIndex = this.findFirstNonLeadAudio();
this.currentAudioIndex = firstNonLeadIndex >= 0 ? firstNonLeadIndex : 0;
this.currentTime = 0;
this.isPlaying = false;
console.log(`🎵 autoPlayCachedAudio: 设置起始索引为${this.currentAudioIndex}(跳过导语)`);
// UI
setTimeout(() => {
this.playAudio();
@ -2946,20 +2965,31 @@ export default {
return;
}
//
const firstAudio = this.currentPageAudios[0];
if (!firstAudio || !firstAudio.url) {
//
const firstNonLeadIndex = this.findFirstNonLeadAudio();
if (firstNonLeadIndex < 0 || firstNonLeadIndex >= this.currentPageAudios.length) {
console.warn('🎵 autoPlayPreloadedAudio: 找不到有效的非导语音频');
return;
}
const firstAudio = this.currentPageAudios[firstNonLeadIndex];
if (!firstAudio || !firstAudio.url) {
console.warn('🎵 autoPlayPreloadedAudio: 第一个非导语音频数据无效');
return;
}
//
this.currentAudioIndex = 0;
//
this.currentAudioIndex = firstNonLeadIndex;
this.currentTime = 0;
this.sliderValue = 0;
this.currentHighlightIndex = 0;
//
const highlightIndex = firstAudio.originalTextIndex !== undefined ? firstAudio.originalTextIndex : firstNonLeadIndex;
this.currentHighlightIndex = highlightIndex;
console.log(`🎵 autoPlayPreloadedAudio: 播放第一个非导语音频,索引=${firstNonLeadIndex}, isLead=${firstAudio.isLead}`);
// 使audioManager
// 使audioManager
audioManager.playAudio(firstAudio.url, 'sentence', { playbackRate: this.playSpeed });
this.isPlaying = true;


Loading…
Cancel
Save