hookehuyr

测试后台音频播放问题

...@@ -10,6 +10,8 @@ export {} ...@@ -10,6 +10,8 @@ export {}
10 declare module '@vue/runtime-core' { 10 declare module '@vue/runtime-core' {
11 export interface GlobalComponents { 11 export interface GlobalComponents {
12 AudioBackground: typeof import('./src/components/audioBackground.vue')['default'] 12 AudioBackground: typeof import('./src/components/audioBackground.vue')['default']
13 + AudioBackground1: typeof import('./src/components/audioBackground1.vue')['default']
14 + copy: typeof import('./src/components/audioBackground copy.vue')['default']
13 Floor: typeof import('./src/components/Floor/index.vue')['default'] 15 Floor: typeof import('./src/components/Floor/index.vue')['default']
14 InfoPopup: typeof import('./src/components/InfoPopup.vue')['default'] 16 InfoPopup: typeof import('./src/components/InfoPopup.vue')['default']
15 InfoPopupLite: typeof import('./src/components/InfoPopupLite.vue')['default'] 17 InfoPopupLite: typeof import('./src/components/InfoPopupLite.vue')['default']
......
1 +<!--
2 + * @Date: 2023-06-12 11:23:10
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2024-09-21 10:57:29
5 + * @FilePath: /map-demo/src/components/audioBackground1.vue
6 + * @Description: 文件描述
7 +-->
8 +<template>
9 + <div v-if="audio_src" class="audio-background-page">
10 + <div @click="handleAudio" :class="['icon', audio_status === 'pause' ? 'play' : 'pause']"></div>
11 + </div>
12 +</template>
13 +
14 +<script>
15 +import { mapState, mapActions } from 'pinia'
16 +import { mainStore } from '@/store'
17 +import $ from 'jquery';
18 +
19 +export default {
20 + data () {
21 + return {
22 + }
23 + },
24 + mounted () {
25 +
26 + },
27 + computed: {
28 + ...mapState(mainStore, ['audio_entity', 'audio_src', 'audio_status'])
29 + },
30 + methods: {
31 + ...mapActions(mainStore, ['changeAudio', 'changeAudioSrc', 'changeAudioStatus']),
32 + handleAudio () {
33 + if (this.audio_status === 'play') {
34 + this.audio_entity.pause();
35 + this.changeAudioStatus('pause');
36 + } else {
37 + this.audio_entity.play();
38 + this.changeAudioStatus('play');
39 + }
40 + }
41 + }
42 +}
43 +</script>
44 +
45 +<style lang="less" scoped>
46 +.audio-background-page {
47 + position: fixed;
48 + right: 1.25rem;
49 + bottom: 17rem;
50 + .icon {
51 + width: 2.5rem;
52 + height: 2.5rem;
53 + border-radius: 50%;
54 + background-size: contain;
55 + }
56 +
57 + .play {
58 + background-image: url('https://cdn.ipadbiz.cn/xys/map/%E6%92%AD%E6%94%BE%E6%9A%82%E5%81%9C@2x.png');
59 + }
60 + .pause {
61 + background-image: url('https://cdn.ipadbiz.cn/xys/map/%E6%92%AD%E6%94%BE@2x.png');
62 + animation: rotate 4s linear infinite;
63 + }
64 +
65 + @keyframes rotate {
66 + 0% {
67 + transform: rotate(0deg);
68 + }
69 + 100% {
70 + transform: rotate(360deg);
71 + }
72 + }
73 +
74 + .paused {
75 + animation-play-state: paused;
76 + }
77 +}
78 +</style>
1 <!-- 1 <!--
2 * @Date: 2024-09-15 22:08:49 2 * @Date: 2024-09-15 22:08:49
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-09-20 18:19:58 4 + * @LastEditTime: 2024-09-21 10:49:05
5 * @FilePath: /map-demo/src/views/bieyuan/info.vue 5 * @FilePath: /map-demo/src/views/bieyuan/info.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -110,7 +110,7 @@ import { storeToRefs } from 'pinia' ...@@ -110,7 +110,7 @@ import { storeToRefs } from 'pinia'
110 import { mainStore } from '@/store'; 110 import { mainStore } from '@/store';
111 111
112 const store = mainStore(); 112 const store = mainStore();
113 -const { audio_status } = storeToRefs(store); 113 +const { audio_status, audio_entity } = storeToRefs(store);
114 114
115 const $route = useRoute(); 115 const $route = useRoute();
116 const $router = useRouter(); 116 const $router = useRouter();
...@@ -146,6 +146,10 @@ const audioList = ref([{ ...@@ -146,6 +146,10 @@ const audioList = ref([{
146 const playAudio = (item, index) => { 146 const playAudio = (item, index) => {
147 audioList.value.forEach(item => item.play = false); 147 audioList.value.forEach(item => item.play = false);
148 audio.value.src = item.src; 148 audio.value.src = item.src;
149 + // 后台有播放器运行时,先暂停
150 + if (audio_status.value === 'play'){
151 + audio_entity.value.pause();
152 + }
149 play_audio_index.value = index; 153 play_audio_index.value = index;
150 let play_status = audio.value.play() // 播放 154 let play_status = audio.value.play() // 播放
151 if (play_status) { 155 if (play_status) {
...@@ -154,8 +158,9 @@ const playAudio = (item, index) => { ...@@ -154,8 +158,9 @@ const playAudio = (item, index) => {
154 console.warn('success'); 158 console.warn('success');
155 item.play = true; 159 item.play = true;
156 // 存放到pinia里面控制 160 // 存放到pinia里面控制
157 - // store.changeAudioSrc(audio.value.src); 161 + store.changeAudio(audio.value);
158 - // store.changeAudioStatus('play'); 162 + store.changeAudioSrc(audio.value.src);
163 + store.changeAudioStatus('play');
159 }).catch((e) => { 164 }).catch((e) => {
160 // 失败 165 // 失败
161 console.log('Operation is too fast, audio play fails') 166 console.log('Operation is too fast, audio play fails')
...@@ -171,14 +176,9 @@ const stopAudio = (item, index) => { ...@@ -171,14 +176,9 @@ const stopAudio = (item, index) => {
171 const audio = ref(new Audio()); 176 const audio = ref(new Audio());
172 177
173 onMounted(() => { 178 onMounted(() => {
174 - // 存放到pinia里面控制
175 - if (store.changeAudio(audio.value)){
176 - store.changeAudio(audio.value);
177 - store.changeAudioStatus('pause');
178 - }
179 }) 179 })
180 180
181 -onUnmounted(() => { 181 +onUnmounted(() => { // 离开页面时关闭音频播放
182 audio.value.pause(); 182 audio.value.pause();
183 store.changeAudioStatus('pause'); 183 store.changeAudioStatus('pause');
184 }) 184 })
......
1 <!-- 1 <!--
2 * @Date: 2023-05-19 14:54:27 2 * @Date: 2023-05-19 14:54:27
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-09-20 18:30:30 4 + * @LastEditTime: 2024-09-21 11:01:31
5 * @FilePath: /map-demo/src/views/bieyuan/map.vue 5 * @FilePath: /map-demo/src/views/bieyuan/map.vue
6 * @Description: 公众地图主体页面 6 * @Description: 公众地图主体页面
7 --> 7 -->
...@@ -57,7 +57,8 @@ ...@@ -57,7 +57,8 @@
57 <div style="padding: 1rem; text-align: center;">{{ dialog_text }}</div> 57 <div style="padding: 1rem; text-align: center;">{{ dialog_text }}</div>
58 </van-dialog> 58 </van-dialog>
59 59
60 - <!-- <audioBackground></audioBackground> --> 60 + <!-- 背景音乐控制 -->
61 + <!-- <audioBackground1></audioBackground1> -->
61 </div> 62 </div>
62 </template> 63 </template>
63 64
...@@ -72,7 +73,7 @@ import { useRect } from '@vant/use'; ...@@ -72,7 +73,7 @@ import { useRect } from '@vant/use';
72 import { mapAPI } from '@/api/map.js' 73 import { mapAPI } from '@/api/map.js'
73 import wx from 'weixin-js-sdk' 74 import wx from 'weixin-js-sdk'
74 import pageInfo from '@/views/bieyuan/info.vue' 75 import pageInfo from '@/views/bieyuan/info.vue'
75 -import audioBackground from '@/components/audioBackground' 76 +import audioBackground1 from '@/components/audioBackground1.vue'
76 import { mapState, mapActions } from 'pinia' 77 import { mapState, mapActions } from 'pinia'
77 import { mainStore } from '@/store' 78 import { mainStore } from '@/store'
78 79
...@@ -133,7 +134,7 @@ const GPS = { ...@@ -133,7 +134,7 @@ const GPS = {
133 }; 134 };
134 135
135 export default { 136 export default {
136 - components: { pageInfo, audioBackground }, 137 + components: { pageInfo, audioBackground1 },
137 data() { 138 data() {
138 return { 139 return {
139 map: '', 140 map: '',
......