修正讲解音频时长显示
- 未加载媒体元数据时默认显示零时长 - 使用音频文件真实媒体时长更新播放器 - 避免使用不准确的接口时长覆盖播放器显示 - 补充音频时长回归测试 Made-with: Proma
This commit is contained in:
@@ -74,9 +74,10 @@ const isAutoplayBlocked = (err: unknown) => {
|
|||||||
|
|
||||||
const syncAudioDuration = () => {
|
const syncAudioDuration = () => {
|
||||||
if (!audioElement) return
|
if (!audioElement) return
|
||||||
duration.value = Number.isFinite(audioElement.duration)
|
const mediaDuration = audioElement.duration
|
||||||
? audioElement.duration
|
duration.value = Number.isFinite(mediaDuration) && mediaDuration > 0
|
||||||
: currentAudio.value?.duration || 0
|
? mediaDuration
|
||||||
|
: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const ensureAudioElement = () => {
|
const ensureAudioElement = () => {
|
||||||
@@ -180,7 +181,7 @@ const stopPlayback = () => {
|
|||||||
loading.value = false
|
loading.value = false
|
||||||
pendingLanguage.value = ''
|
pendingLanguage.value = ''
|
||||||
currentTime.value = 0
|
currentTime.value = 0
|
||||||
duration.value = currentAudio.value?.duration || 0
|
duration.value = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateDetailRouteLanguage = (route: string | undefined, lang: AudioLanguage) => {
|
const updateDetailRouteLanguage = (route: string | undefined, lang: AudioLanguage) => {
|
||||||
@@ -246,7 +247,7 @@ const play = async (audio: AudioItem, options: GlobalAudioPlayOptions = {}) => {
|
|||||||
|
|
||||||
if (isNewAudio) {
|
if (isNewAudio) {
|
||||||
currentTime.value = 0
|
currentTime.value = 0
|
||||||
duration.value = audio.duration || 0
|
duration.value = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.getAttribute('src') !== audio.audioUrl) {
|
if (element.getAttribute('src') !== audio.audioUrl) {
|
||||||
|
|||||||
@@ -372,14 +372,9 @@ const formatDetailAudioTime = (seconds?: number) => {
|
|||||||
|
|
||||||
return `${minutes}:${remainSeconds.toString().padStart(2, '0')}`
|
return `${minutes}:${remainSeconds.toString().padStart(2, '0')}`
|
||||||
}
|
}
|
||||||
const detailAudioDurationSeconds = computed(() => {
|
const detailAudioDurationSeconds = computed(() => (
|
||||||
if (!isCurrentDetailAudioTarget.value) return exhibit.value.audio.duration || 0
|
isCurrentDetailAudioTarget.value ? globalAudioPlayer.duration.value : 0
|
||||||
|
))
|
||||||
return globalAudioPlayer.duration.value
|
|
||||||
|| globalAudioPlayer.currentAudio.value?.duration
|
|
||||||
|| exhibit.value.audio.duration
|
|
||||||
|| 0
|
|
||||||
})
|
|
||||||
const detailAudioCurrentSeconds = computed(() => (
|
const detailAudioCurrentSeconds = computed(() => (
|
||||||
isCurrentDetailAudioTarget.value ? globalAudioPlayer.currentTime.value : 0
|
isCurrentDetailAudioTarget.value ? globalAudioPlayer.currentTime.value : 0
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ describe('讲解详情音频优先布局', () => {
|
|||||||
expect(wrapper.get('.content-section').classes()).toContain('is-english')
|
expect(wrapper.get('.content-section').classes()).toContain('is-english')
|
||||||
expect(wrapper.find('.section-title').exists()).toBe(false)
|
expect(wrapper.find('.section-title').exists()).toBe(false)
|
||||||
expect(wrapper.get('.section-text').text()).toContain('detailed English narration')
|
expect(wrapper.get('.section-text').text()).toContain('detailed English narration')
|
||||||
expect(wrapper.get('.detail-audio-time').text()).toBe('0:00 / 1:21')
|
expect(wrapper.get('.detail-audio-time').text()).toBe('0:00 / 0:00')
|
||||||
expect(wrapper.get('.detail-audio-speed').attributes('aria-label')).toBe('播放速度 1.0倍')
|
expect(wrapper.get('.detail-audio-speed').attributes('aria-label')).toBe('播放速度 1.0倍')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user