浏览代码

清理资源

丸子 3 月之前
父节点
当前提交
5a8d9d9f90
共有 1 个文件被更改,包括 12 次插入2 次删除
  1. 12 2
      src/views/laboratory/ExperimentalInterface.vue

+ 12 - 2
src/views/laboratory/ExperimentalInterface.vue

@@ -140,6 +140,8 @@ import ImageToVideo from "@/components/ai/video/ImageToVideo.vue";
 import MapGame from "@/components/blockly/MapGame.vue";
 // 根据ID获取课程列表
 import { getBlocklyByTypeId } from '@/api/programming/index.js'
+// 导入音频播放器
+import { useAudioPlayer } from '@/api/tts/useAudioPlayer';
 
 // 定义常量
 const CONSTANTS = {
@@ -152,6 +154,8 @@ const CONSTANTS = {
 const router = useRouter() // 获取当前路由对象
 // 渲染页面标题
 const boxIconTitle = ref('')
+// 音频播放器实例
+const { stopPlayback } = useAudioPlayer();
 // 定义组件的props
 const props = defineProps({
   courseData: {
@@ -215,6 +219,8 @@ const playPreviousVideo = () => {
   if (props.courseList && props.courseList.length > 0) {
     const currentIndex = currentCourseIndex.value
     if (currentIndex > 0) {
+      // 停止音频播放并清理资源
+      stopPlayback();
       const previousCourse = props.courseList[currentIndex - 1]
       // 更新当前课程数据
       handleParentCourseData(previousCourse)
@@ -230,8 +236,9 @@ const playNextVideo = () => {
   if (props.courseList && props.courseList.length > 0) {
     const currentIndex = currentCourseIndex.value
     if (currentIndex !== -1 && currentIndex < props.courseList.length - 1) {
+      // 停止音频播放并清理资源
+      stopPlayback();
       const nextCourse = props.courseList[currentIndex + 1]
-
       // 更新当前课程数据
       handleParentCourseData(nextCourse)
       courseId.value = course.value.id
@@ -408,7 +415,10 @@ onMounted(async () => {
 })
 
 // 清理函数
-onUnmounted(() => {})
+onUnmounted(() => {
+  // 组件卸载时清理音频资源
+  stopPlayback();
+})
 
 // 保存视频/bockly进度接口
 const handleSaveProgress = async (type, progress) => {