gemercheung 2 anos atrás
pai
commit
c3dcb8b9b4

+ 6 - 16
packages/qjkankan-view/src/components/Fdkk/index.vue

@@ -45,13 +45,7 @@
 </template>
 
 <script setup>
-import {
-  ref,
-  computed,
-  onUnmounted,
-  onMounted,
-  nextTick,
-} from "vue";
+import { ref, computed, onUnmounted, onMounted, nextTick } from "vue";
 import { useStore } from "vuex";
 import browser from "@/utils/browser";
 
@@ -111,8 +105,9 @@ const handleMessage = (res) => {
 
     // V4场景本身的背景音乐 (同时可判断场景已经加载完成)
     if (event == "fdkkBgmLink") {
-      console.log("fdkkBgmLink", params.music);
-      store.dispatch("audio/initV4BGM", params.music);
+      const url = params.music || "";
+      console.log("fdkkBgmLink", url);
+      store.dispatch("audio/initV4BGM", url);
       // loading完毕
       getApp().Scene.emit("ready");
     }
@@ -132,14 +127,9 @@ const handleMessage = (res) => {
       console.error("toggleBgmStatus", params);
       // debugger;
       if (params.status) {
-        // if (unref(isHasV4BGM)) {
-        //   store.dispatch("audio/playBGM", 2);
-        // } else {
-        //   store.dispatch("audio/playBGM", 0);
-        // }
-        // store.dispatch("audio/resumeBGM");
+
       } else {
-        // store.dispatch("audio/pauseBGM");
+
       }
     }
 

+ 11 - 6
packages/qjkankan-view/src/components/UIGather/control.vue

@@ -36,7 +36,7 @@
       <img
         :src="
           require(`@/assets/images/icon/${
-            isPlayNormalBGM && isCurrentPlaying
+            (isPlayNormalBGM || isPlayV4BGM) && isCurrentPlaying
               ? 'music@2x.png'
               : 'music_disabled@2x.png'
           }`)
@@ -131,6 +131,7 @@ const isHasExplanationBGM = computed(
 );
 //BMG playing音乐
 const isPlayNormalBGM = computed(() => store.getters["audio/isPlayNormalBGM"]);
+const isPlayV4BGM = computed(() => store.getters["audio/isPlayV4BGM"]);
 const isPlayExplanationBGM = computed(
   () => store.getters["audio/isPlayExplanationBGM"]
 );
@@ -186,13 +187,17 @@ const onLink = () => {
 };
 
 const onIsBGM = () => {
-  if (!unref(isPlayNormalBGM)) {
-    store.dispatch("audio/playBGM", 0);
-  } else {
-    if (unref(isCurrentPlaying)) {
-      store.dispatch("audio/pauseBGM");
+  if (unref(isHasV4BGM)) {
+    if (!unref(isCurrentPlaying)) {
+      store.dispatch("audio/playBGM", 2);
     } else {
+      store.dispatch("audio/pauseBGM");
+    }
+  } else {
+    if (!unref(isCurrentPlaying)) {
       store.dispatch("audio/playBGM", 0);
+    } else {
+      store.dispatch("audio/pauseBGM");
     }
   }
 };

+ 1 - 1
packages/qjkankan-view/src/hooks/useAudio.js

@@ -129,7 +129,6 @@ class AudioPlayer {
             this[method] = emitter[method]
         })
         this.audio = null
-
         this.switchUrl = debounce(this.switchUrlSource, 300).bind(this);
         this.play = debounce(this.toPlay, 300).bind(this);
         this.init();
@@ -140,6 +139,7 @@ class AudioPlayer {
 
     switchUrlSource(url, autoplay, loop) {
         if ('unload' in this.audio) {
+            console.log('switchUrlSource-1');
             this.audio.unload();
         } else {
             console.log('switchUrlSource-2');

+ 8 - 3
packages/qjkankan-view/src/store/modules/audio.js

@@ -134,10 +134,11 @@ export default {
                     newURL = url
                 }
             }
-
             commit('setV4BGM', { url: newURL, repeat: true, isAuto: true });
         },
-        playBGM({ commit, getters, state }, type) {
+        playBGM({ commit, getters, state, dispatch }, type) {
+            console.warn('~~playBGM~~', type);
+            debugger;
             const index = getters['currentAudio'].order;
             const order = index + 1;
             const target = getters['bgmList'].find(i => i.type === type);
@@ -158,6 +159,10 @@ export default {
                 }
             } else {
                 console.error('当前BGM没有URL', target);
+                if (type === 2) {
+                    //fallback
+                    dispatch('playBGM', 0);
+                }
             }
 
         },
@@ -171,7 +176,7 @@ export default {
         resumeBGM() {
             const { currentPlayer } = useAudio();
             if (unref(currentPlayer)) {
-                currentPlayer.value.play();
+                currentPlayer.value.resume();
             }
         },
         updatePlayerStatus({ commit }, status) {