MP3及MP4预览页面,关闭后仍然播放的问题

This commit is contained in:
yangjun 2025-08-01 15:16:29 +08:00
parent 62a144269a
commit 7770ca2941
1 changed files with 12 additions and 3 deletions

View File

@ -232,7 +232,7 @@
<!-- 音频播放 -->
<a-modal v-model:visible="showAudioModal" title="音频播放" :footer="null" @cancel="closeAudioModal"
:bodyStyle="{ padding: '0', maxHeight: '80vh', overflow: 'auto' }" :keyboard="true">
<audio controls style="width: 100%; display: block; margin: 20px auto;">
<audio ref="audioPlayer" controls style="width: 100%; display: block; margin: 20px auto;">
<source :src="audioUrl">
您的浏览器不支持音频播放
</audio>
@ -241,7 +241,7 @@
<!-- 视频播放 -->
<a-modal v-model:visible="showVideoModal" title="视频播放" :footer="null" @cancel="closeVideoModal"
:bodyStyle="{ padding: '0', maxHeight: '80vh', overflow: 'auto' }">
<video controls style="width: 100%; max-height: 70vh; display: block; margin: 0 auto;">
<video ref="videoPlayer" controls style="width: 100%; max-height: 70vh; display: block; margin: 0 auto;">
<source :src="videoUrl">
您的浏览器不支持视频播放
</video>
@ -583,6 +583,7 @@ function onEmotionTagClose() {
const showAudioModal = ref(false); //
const audioUrl = ref(''); // URL
const audioPlayer = ref(null);
//
const openAudioModal = (url) => {
@ -592,12 +593,17 @@ const openAudioModal = (url) => {
//
const closeAudioModal = () => {
if (audioPlayer.value) {
audioPlayer.value.pause(); //
audioPlayer.value.currentTime = 0; //
}
showAudioModal.value = false;
audioUrl.value = '';
};
const showVideoModal = ref(false); //
const videoUrl = ref(''); // URL
const videoPlayer = ref(null);
//
const openVideoModal = (url) => {
@ -607,12 +613,15 @@ const openVideoModal = (url) => {
//
const closeVideoModal = () => {
if (videoPlayer.value) {
videoPlayer.value.pause(); //
videoPlayer.value.currentTime = 0; //
}
showVideoModal.value = false;
videoUrl.value = '';
};
//
const audioPlayer = ref<HTMLAudioElement | null>(null);
const currentPlayingAudio = ref<string | null>(null);
const isPlaying = ref(false);