hookehuyr

新增音频播放测试

...@@ -5,19 +5,29 @@ ...@@ -5,19 +5,29 @@
5 <div class="popup-content" style="height: 13.5rem;"> 5 <div class="popup-content" style="height: 13.5rem;">
6 <div style="position: relative;"> 6 <div style="position: relative;">
7 <h3 class="view-name">三宝楼</h3> 7 <h3 class="view-name">三宝楼</h3>
8 - <van-icon @click="close" name="cross" size="1.25rem" style="position: absolute; right: 0.75rem; top: 0.75rem;" /> 8 + <van-icon @click="close" name="cross" size="1.25rem"
9 + style="position: absolute; right: 0.75rem; top: 0.75rem;" />
9 </div> 10 </div>
10 <img class="view-photo" 11 <img class="view-photo"
11 src="https://img0.baidu.com/it/u=3974116483,397969091&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=496"> 12 src="https://img0.baidu.com/it/u=3974116483,397969091&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=496">
12 <p class="introduction" style="padding: 0.5rem; padding-bottom: 0;">尊敬的游客朋友们您好,欢迎来到西园寺,您现在所到的地方是“三宝楼......</p> 13 <p class="introduction" style="padding: 0.5rem; padding-bottom: 0;">尊敬的游客朋友们您好,欢迎来到西园寺,您现在所到的地方是“三宝楼......</p>
13 - <div class="control-play"><span></span></div> 14 + <div v-if="!is_play" @click="play()" class="control-play" style="text-align: center;">
14 - <div @click="showDetail" class="show-details" style="color: white; text-align: center; line-height: 3rem;">详情</div> 15 + <van-icon name="play-circle-o" size="2rem" color="#FFF" style="margin-top: 0.5rem;" />
15 </div> 16 </div>
17 + <div v-else @click="pause()" class="control-play" style="text-align: center;">
18 + <van-icon name="pause-circle-o" size="2rem" color="#FFF" style="margin-top: 0.5rem;" />
16 </div> 19 </div>
20 + <div @click="showDetail" class="show-details" style="color: white; text-align: center; line-height: 3rem;">详情
21 + </div>
22 + </div>
23 + </div>
24 + </div>
25 + <div class="leaflet-popup-tip-container" style="left: 50%; position: relative;">
26 + <div class="leaflet-popup-tip"></div>
17 </div> 27 </div>
18 - <div class="leaflet-popup-tip-container" style="left: 50%; position: relative;"><div class="leaflet-popup-tip"></div></div>
19 28
20 - <van-popup teleport="body" v-model:show="show_popup" position="bottom" :overlay="true" :style="{ padding: '1rem', height: '100%' }"> 29 + <van-popup teleport="body" v-model:show="show_popup" position="bottom" :overlay="true"
30 + :style="{ padding: '1rem', height: '100%' }">
21 <van-icon name="cross" size="1.35rem" @click="show_popup = false" style="float: right; color: gray;" /> 31 <van-icon name="cross" size="1.35rem" @click="show_popup = false" style="float: right; color: gray;" />
22 <div class="popup-wrapper"> 32 <div class="popup-wrapper">
23 <div class="title"> 33 <div class="title">
...@@ -34,6 +44,7 @@ ...@@ -34,6 +44,7 @@
34 </template> 44 </template>
35 45
36 <script> 46 <script>
47 +
37 export default { 48 export default {
38 props: { 49 props: {
39 infoWindow: { 50 infoWindow: {
...@@ -45,12 +56,15 @@ export default { ...@@ -45,12 +56,15 @@ export default {
45 default: '' 56 default: ''
46 } 57 }
47 }, 58 },
48 - data () { 59 + data() {
49 return { 60 return {
50 show_popup: false, 61 show_popup: false,
51 popup_title: '', 62 popup_title: '',
52 popup_content: '', 63 popup_content: '',
53 video_src: '', 64 video_src: '',
65 + ind: '',
66 + is_play: false,
67 + audio: new Audio()
54 } 68 }
55 }, 69 },
56 methods: { 70 methods: {
...@@ -58,12 +72,51 @@ export default { ...@@ -58,12 +72,51 @@ export default {
58 close() { 72 close() {
59 // 高德地图信息窗关闭的api 73 // 高德地图信息窗关闭的api
60 this.infoWindow.close() 74 this.infoWindow.close()
75 + // 处理音频
76 + this.voice_pause();
77 + this.audio.currentTime = 0
61 }, 78 },
62 - showDetail () { 79 + showDetail() {
63 this.show_popup = true; 80 this.show_popup = true;
64 this.popup_title = '三宝楼'; 81 this.popup_title = '三宝楼';
65 this.popup_content = '尊敬的游客朋友们您好,欢迎来到西园寺,您现在所到的地方是“三宝楼......'; 82 this.popup_content = '尊敬的游客朋友们您好,欢迎来到西园寺,您现在所到的地方是“三宝楼......';
66 this.video_src = 'https://video.pearvideo.com/mp4/short/20200209/cont-1650197-14888002-hd.mp4' 83 this.video_src = 'https://video.pearvideo.com/mp4/short/20200209/cont-1650197-14888002-hd.mp4'
84 + },
85 + play () {
86 + this.voice_play('https://file.365daoyou.cn/mimi-001_1505799708494-k3xkyzv8', 0)
87 + },
88 + pause () {
89 + this.voice_pause()
90 + },
91 + // 声音播放
92 + voice_play(src, index) {
93 + this.audio.src = src
94 + if (this.ind) {
95 + // audio.pause(); //暂停
96 + this.audio.currentTime = 0
97 + this.ind = 0
98 + return
99 + }
100 + this.ind = index
101 + let play_status = this.audio.play() // 播放
102 + if (play_status) {
103 + this.is_play = true;
104 + play_status.then(() => {
105 + // 音频加载成功
106 + // 音频的播放需要耗时
107 + console.log(this.audio.duration)
108 + setTimeout(() => { // 后续操作(同为播放完成)
109 + this.ind = 0
110 + }, this.audio.duration * 1000) // audio.duration 为音频的时长单位为秒
111 + }).catch((e) => {
112 + // 失败
113 + console.log('Operation is too fast, audio play fails')
114 + })
115 + }
116 + },
117 + voice_pause () {
118 + this.audio.pause();
119 + this.is_play = false;
67 } 120 }
68 } 121 }
69 } 122 }
......
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: 2023-05-31 14:05:43 4 + * @LastEditTime: 2023-05-31 15:25:25
5 * @FilePath: /map-demo/src/views/index.vue 5 * @FilePath: /map-demo/src/views/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
8 <template> 8 <template>
9 <div style="height: 100vh; position: relative; overflow: hidden;"> 9 <div style="height: 100vh; position: relative; overflow: hidden;">
10 <div id="container"></div> 10 <div id="container"></div>
11 - <div id="abc" class="nav-bar-wrapper"> 11 + <div class="nav-bar-wrapper">
12 <div class="hideScrollBar" 12 <div class="hideScrollBar"
13 style="display: flex; overflow-x: scroll; overflow-y: hidden; -webkit-overflow-scrolling: touch; position: relative;"> 13 style="display: flex; overflow-x: scroll; overflow-y: hidden; -webkit-overflow-scrolling: touch; position: relative;">
14 <div style="width: 30%; flex-shrink: 0; padding-top: 1rem;" :class="[isActive === 0 ? 'checked' : '', 'item']" 14 <div style="width: 30%; flex-shrink: 0; padding-top: 1rem;" :class="[isActive === 0 ? 'checked' : '', 'item']"
......