Browse Source

尝试修复音频无法解锁的问题

zhangyujun 3 years ago
parent
commit
7017ae0090
2 changed files with 15 additions and 3 deletions
  1. 3 1
      src/hooks/light/audio.ts
  2. 12 2
      src/store/index.ts

+ 3 - 1
src/hooks/light/audio.ts

@@ -19,7 +19,6 @@ export function useAudio() {
         pauseAudio()
         sound = new Howl({
             src: url,
-            html5: true,
             xhr: {
                 method: 'GET',
                 headers: {
@@ -29,6 +28,9 @@ export function useAudio() {
             }
         });
         return new Promise((resolve, reject) => {
+            sound.on('unlock',()=>{
+                console.log("我已经解锁了")
+            })
             sound.once("load", function () {
                 let id = sound.play();
                 if (id) {

+ 12 - 2
src/store/index.ts

@@ -1,6 +1,7 @@
 import { createStore } from "vuex";
 import createPersistedState from "vuex-persistedstate";
 import dayjs from "dayjs";
+import { Howl } from "howler";
 const store = createStore({
   plugins: [createPersistedState()],
   state: () => ({
@@ -8,7 +9,16 @@ const store = createStore({
     userData: {
       schoolName: ""
     },
-    lightAudio: null,
+    lightAudio: new Howl({
+      src: "",
+      xhr: {
+        method: 'GET',
+        headers: {
+          Authorization: 'Bearer:' + store.state.token,
+        },
+        withCredentials: true,
+      }
+    }),
     lightConfig: {
       interval: 5,
       directives: 5,
@@ -44,7 +54,7 @@ const store = createStore({
       const userTime: number = dayjs(store.getters.getUserData.expireTime).valueOf();
       const currentTime: number = dayjs().valueOf();
       //return (userTime - currentTime) > 0
-       return true
+      return true
     }
   },
   mutations: {