|
@@ -42,14 +42,14 @@
|
|
|
@click="handlePlayAudio(item)">
|
|
|
</image>
|
|
|
<view class="name">{{ item.voiceName }}</view>
|
|
|
- <view class="time">{{item.currentPlayTime|formarVoiceTime}} / {{ item.voicePlaySeconds|formarVoiceTime }}</view>
|
|
|
+ <view class="time">{{activeAudioUrl==item.voiceUrl?activeAudioTime:0|formarVoiceTime}} / {{ item.voicePlaySeconds|formarVoiceTime }}</view>
|
|
|
<slider
|
|
|
class="audio-slider"
|
|
|
activeColor="#e3b377"
|
|
|
:max="item.voicePlaySeconds"
|
|
|
- :value="item.currentPlayTime"
|
|
|
+ :value="activeAudioUrl==item.voiceUrl?activeAudioTime:0"
|
|
|
@change="handleAudioSliderChange($event,item)"
|
|
|
- block-size="16"
|
|
|
+ block-size="18"
|
|
|
/>
|
|
|
</view>
|
|
|
</view>
|
|
@@ -151,6 +151,7 @@ export default {
|
|
|
audioList: [], //音频数据
|
|
|
|
|
|
activeAudioUrl:'',//正在播放的背景音频地址
|
|
|
+ activeAudioTime:0,//
|
|
|
|
|
|
pupData: {
|
|
|
show: false,
|
|
@@ -165,6 +166,9 @@ export default {
|
|
|
this.getDetail();
|
|
|
this.getAudios()
|
|
|
},
|
|
|
+ onUnload(){
|
|
|
+ this.handleSaveAudioMsg()
|
|
|
+ },
|
|
|
onShareAppMessage() {
|
|
|
let title=''
|
|
|
if(this.info.firstActivityTypeId==1){
|
|
@@ -247,69 +251,106 @@ export default {
|
|
|
async getAudios() {
|
|
|
const res = await apiActivityAudios({ activity_id: Number(this.id) });
|
|
|
if (res.code === 200&&res.data) {
|
|
|
+ const audioPlayPaused=this.globalBgMusic.paused// true 当前没有音频在播放
|
|
|
+ if(audioPlayPaused===false){// 当前有音频在播放
|
|
|
+ this.activeAudioUrl=uni.getStorageSync('activityAudioUrl')
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('是否有音频在播放',audioPlayPaused===false);
|
|
|
+
|
|
|
this.audioList = res.data.map(item=>{
|
|
|
- return {...item,currentPlayTime:0,playStatus:false}
|
|
|
+ let obj={...item,playStatus:false}
|
|
|
+ if(audioPlayPaused===false){
|
|
|
+ if(item.voiceUrl==this.globalBgMusic.src){
|
|
|
+ obj.playStatus=true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return obj
|
|
|
});
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- //音频进度条拖动
|
|
|
- handleAudioSliderChange(e,item){
|
|
|
- const value=e.detail.value
|
|
|
- item.currentPlayTime=value
|
|
|
|
|
|
- // 如果当前activeAudioUrl 不等于拖动的这个音频
|
|
|
- if(item.voiceUrl!=this.activeAudioUrl){
|
|
|
- if(this.activeAudioUrl){
|
|
|
- // 先暂停
|
|
|
- this.globalBgMusic.pause()
|
|
|
+ if(audioPlayPaused===false){
|
|
|
+ this.activeAudioTime=this.globalBgMusic.currentTime
|
|
|
+ this.globalBgMusic.onTimeUpdate(()=>{
|
|
|
+ this.activeAudioTime=parseInt(this.globalBgMusic.currentTime)
|
|
|
+ })
|
|
|
}
|
|
|
- this.handlePlayAudio(item)
|
|
|
- }else{
|
|
|
- this.globalBgMusic.seek(value)
|
|
|
}
|
|
|
},
|
|
|
|
|
|
// 播放音频
|
|
|
handlePlayAudio(e){
|
|
|
- if(this.activeAudioUrl==e.voiceUrl&&e.playStatus){
|
|
|
+ if(this.globalBgMusic.src==e.voiceUrl&&e.playStatus){// 同一个音频 并且是播放状态 则暂停
|
|
|
+ console.log('同一个音频 并且是播放状态 则暂停');
|
|
|
+ console.log('音频实例',this.globalBgMusic.src);
|
|
|
this.globalBgMusic.pause()
|
|
|
+ }else if(this.globalBgMusic.src==e.voiceUrl&&!e.playStatus){//同一个音频 并且是暂停状态 则直接播放
|
|
|
+ console.log('同一个音频 并且是暂停状态 则直接播放');
|
|
|
+ console.log('音频实例',this.globalBgMusic.src);
|
|
|
+ this.globalBgMusic.play()
|
|
|
}else{
|
|
|
this.globalBgMusic.title=e.voiceName
|
|
|
this.globalBgMusic.src=e.voiceUrl
|
|
|
-
|
|
|
- console.log(e.currentPlayTime);
|
|
|
- // setTimeout(()=>{
|
|
|
- this.globalBgMusic.startTime=e.currentPlayTime
|
|
|
- this.globalBgMusic.seek(e.currentPlayTime)
|
|
|
-
|
|
|
- // },10)
|
|
|
-
|
|
|
+ this.activeAudioUrl=e.voiceUrl
|
|
|
+ this.activeAudioTime=0
|
|
|
}
|
|
|
|
|
|
this.globalBgMusic.onCanplay(()=>{
|
|
|
+ console.log('onCanplay');
|
|
|
this.globalBgMusic.play()
|
|
|
})
|
|
|
|
|
|
- this.globalBgMusic.onPlay(res=>{
|
|
|
- this.activeAudioUrl=e.voiceUrl
|
|
|
+ this.globalBgMusic.onPlay(()=>{
|
|
|
+ console.log('onplay');
|
|
|
e.playStatus=true
|
|
|
})
|
|
|
this.globalBgMusic.onPause(()=>{
|
|
|
+ console.log('onPause');
|
|
|
e.playStatus=false
|
|
|
})
|
|
|
this.globalBgMusic.onStop(()=>{
|
|
|
+ console.log('onStop');
|
|
|
e.playStatus=false
|
|
|
+ this.activeAudioTime=0
|
|
|
})
|
|
|
this.globalBgMusic.onEnded(()=>{
|
|
|
+ console.log('onEnded');
|
|
|
e.playStatus=false
|
|
|
- e.currentPlayTime=0
|
|
|
+ this.activeAudioTime=0
|
|
|
+ })
|
|
|
+ this.globalBgMusic.onError((e)=>{
|
|
|
+ console.log('onError',e);
|
|
|
})
|
|
|
this.globalBgMusic.onTimeUpdate(()=>{
|
|
|
- e.currentPlayTime=parseInt(this.globalBgMusic.currentTime)
|
|
|
+ if(this.globalBgMusic.src==e.voiceUrl){
|
|
|
+ this.activeAudioTime=parseInt(this.globalBgMusic.currentTime)
|
|
|
+ }
|
|
|
})
|
|
|
},
|
|
|
|
|
|
+ //音频进度条拖动
|
|
|
+ handleAudioSliderChange(e,item){
|
|
|
+ const value=e.detail.value
|
|
|
+ item.currentPlayTime=value
|
|
|
+ // 如果当前activeAudioUrl 不等于拖动的这个音频
|
|
|
+ if(item.voiceUrl!=this.globalBgMusic.src){
|
|
|
+ this.handlePlayAudio(item)
|
|
|
+ }else{
|
|
|
+ this.globalBgMusic.seek(value)
|
|
|
+ this.globalBgMusic.play()
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ // 存储音频播放的信息
|
|
|
+ handleSaveAudioMsg(){
|
|
|
+ // 当音频暂停(不是停止)时 主动调一次停止
|
|
|
+ const audioPlayPaused=this.globalBgMusic.paused
|
|
|
+ if(audioPlayPaused===true){
|
|
|
+ this.globalBgMusic.stop()
|
|
|
+ }
|
|
|
+ uni.setStorageSync('activityAudioUrl',this.activeAudioUrl)
|
|
|
+ },
|
|
|
+
|
|
|
// 点击信息项
|
|
|
handleClickInfoItem(e) {
|
|
|
if (e.type === "tel" && e.text) {
|