Commit 47252085 authored by songrui's avatar songrui

音频播放修改

parent bdc6452d
...@@ -25,7 +25,8 @@ import { showToast } from 'vant' ...@@ -25,7 +25,8 @@ import { showToast } from 'vant'
export default { export default {
props: { props: {
file: { default: () => ({}) } file: { default: () => ({}) },
activeMediaUrl: { default: '' }
}, },
data() { data() {
return { return {
...@@ -50,6 +51,8 @@ export default { ...@@ -50,6 +51,8 @@ export default {
methods: { methods: {
init() { init() {
this.player = new musicPlayer(this.$refs.audio) this.player = new musicPlayer(this.$refs.audio)
this.player.init()
this.player.setSrc(this.file.annexUrl)
this.player.audioEl.onended = () => { this.player.audioEl.onended = () => {
console.log('播放结束') console.log('播放结束')
this.stop() this.stop()
...@@ -62,19 +65,16 @@ export default { ...@@ -62,19 +65,16 @@ export default {
} }
if (!this.player.audioCtx) { if (!this.player.audioCtx) {
this.player.init() this.player.init()
this.player.setSrc(item.annexUrl)
} }
if (this.player.duration && item.annexId === this.activeAudio.annexId) {
if (this.player.playing) { if (this.player.playing) {
this.stop() this.stop()
} else { } else {
this.player.audioEl.play() this.player.audioEl.play()
this.player.playing = true
}
return
}
this.player.setSrc(item.annexUrl)
this.activeAudio = item this.activeAudio = item
this.player.playing = true this.player.playing = true
this.$emit('play', item)
}
console.log('this.player', this.player) console.log('this.player', this.player)
}, },
stop() { stop() {
...@@ -95,6 +95,14 @@ export default { ...@@ -95,6 +95,14 @@ export default {
this.player.progressChange(value) this.player.progressChange(value)
this.player.playing = true this.player.playing = true
} }
},
watch: {
activeMediaUrl(val) {
console.log('activeMediaUrl', val)
if (val !== this.file.annexUrl) {
this.stop()
}
}
} }
} }
</script> </script>
......
...@@ -45,6 +45,7 @@ export default { ...@@ -45,6 +45,7 @@ export default {
start(item) { start(item) {
this.activeVideo = item this.activeVideo = item
this.visible = true this.visible = true
this.$emit('play', item)
} }
} }
} }
......
...@@ -70,7 +70,6 @@ export class musicPlayer { ...@@ -70,7 +70,6 @@ export class musicPlayer {
this.audioEl.oncanplay = () => { this.audioEl.oncanplay = () => {
console.log('可播放') console.log('可播放')
setTimeout(() => { setTimeout(() => {
this.audioEl.play()
this.getAudioSource() this.getAudioSource()
}, 100) }, 100)
} }
......
...@@ -144,10 +144,12 @@ ...@@ -144,10 +144,12 @@
</div> </div>
</div> </div>
<div class="card mt-2" v-if="detailInfo?.publicizeType?.includes(3)"> <div class="card mt-2" v-if="detailInfo?.publicizeType?.includes(3)">
<Mp4 :files="mp4List"/> <Mp4 :files="mp4List" :activeMediaUrl="activeMediaUrl"
@play="e => activeMediaUrl = e.annexUrl"/>
</div> </div>
<div class="card flex flex-col mt-2" style="row-gap: .06rem;" v-if="detailInfo?.publicizeType?.includes(2)"> <div class="card flex flex-col mt-2" style="row-gap: .06rem;" v-if="detailInfo?.publicizeType?.includes(2)">
<Mp3 :file="item" v-for="item in mp3List" :key="item.annexId"/> <Mp3 :file="item" v-for="item in mp3List" :key="item.annexId" :activeMediaUrl="activeMediaUrl"
@play="e => activeMediaUrl = e.annexUrl"/>
</div> </div>
</div> </div>
</van-collapse-item> </van-collapse-item>
...@@ -278,6 +280,7 @@ export default { ...@@ -278,6 +280,7 @@ export default {
{ title: '随访科室', key: 'visitOfficeName' }, { title: '随访科室', key: 'visitOfficeName' },
{ title: '随访医生', key: 'visitDoctorName' } { title: '随访医生', key: 'visitDoctorName' }
], ],
activeMediaUrl: ''
} }
}, },
computed: { computed: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment