|
@@ -1,20 +1,17 @@
|
|
|
import { IconMusic } from "@/assets/icons";
|
|
|
import { isWeixinBrowser } from "@/controllers/wxController";
|
|
|
import { useEditor } from "@/modules/editor";
|
|
|
-import {
|
|
|
- PauseCircleOutlined,
|
|
|
- PlayCircleOutlined,
|
|
|
- LoadingOutlined,
|
|
|
-} from "@ant-design/icons-vue";
|
|
|
+import { PauseCircleOutlined, PlayCircleOutlined } from "@ant-design/icons-vue";
|
|
|
import { css } from "@linaria/core";
|
|
|
-import { Button, Slider, Spin } from "ant-design-vue";
|
|
|
+import { Button, Slider } from "ant-design-vue";
|
|
|
import { Howl } from "howler";
|
|
|
+import { nanoid } from "nanoid";
|
|
|
import { defineComponent, reactive, ref, watch } from "vue";
|
|
|
import { bool, number } from "vue-types";
|
|
|
declare const WeixinJSBridge: any;
|
|
|
export const PageMusic = defineComponent({
|
|
|
setup() {
|
|
|
- const { store, helper } = useEditor();
|
|
|
+ const { store, helper, controls } = useEditor();
|
|
|
const state = reactive({
|
|
|
playStatus: false,
|
|
|
duration: 0,
|
|
@@ -22,6 +19,7 @@ export const PageMusic = defineComponent({
|
|
|
muted: true,
|
|
|
});
|
|
|
const rootComp = helper.findRootComp();
|
|
|
+ let audioKey = nanoid();
|
|
|
let audioBgm = ref();
|
|
|
|
|
|
const initAudioBgm = () => {
|
|
@@ -31,10 +29,10 @@ export const PageMusic = defineComponent({
|
|
|
loop: store.isEditMode ? false : true,
|
|
|
preload: true,
|
|
|
HTML5: true,
|
|
|
- autoplay: store.isEditMode ? false : true,
|
|
|
});
|
|
|
audioBgm.value.on("load", () => {
|
|
|
state.duration = audioBgm.value.duration();
|
|
|
+ controls.mediaCtrl.setMediasInstance(audioKey, audioBgm.value);
|
|
|
if (!store.isEditMode) {
|
|
|
if (isWeixinBrowser()) {
|
|
|
WeixinJSBridge.invoke(
|
|
@@ -45,6 +43,8 @@ export const PageMusic = defineComponent({
|
|
|
},
|
|
|
false
|
|
|
);
|
|
|
+ } else {
|
|
|
+ playAudio(true);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -55,14 +55,20 @@ export const PageMusic = defineComponent({
|
|
|
console.log("音频播放失败");
|
|
|
});
|
|
|
audioBgm.value.on("play", () => {
|
|
|
+ controls.mediaCtrl.pauseOtherMedia(audioKey);
|
|
|
if (!state.playStatus) {
|
|
|
state.playStatus = true;
|
|
|
}
|
|
|
playStep();
|
|
|
});
|
|
|
- audioBgm.value.on("end", () => {
|
|
|
+ audioBgm.value.on("pause", () => {
|
|
|
audioRest();
|
|
|
});
|
|
|
+ audioBgm.value.on("end", () => {
|
|
|
+ if (store.isEditMode) {
|
|
|
+ audioRest();
|
|
|
+ }
|
|
|
+ });
|
|
|
};
|
|
|
initAudioBgm();
|
|
|
const playStep = () => {
|