Commit 01d98f5d authored by wangxuelai's avatar wangxuelai

Merge remote-tracking branch 'origin/sj-dev-v5' into develop-officialweb

parents ecba467b af275c73
// src/pages/websiteindex/clocklist.js
import {
LocalStorage
LocalStorage,
audioorigin,
scenQueryGet,
} from '../../../utilities/index.js';
import {
clockList,
......@@ -53,7 +55,8 @@ Page({
this.setData({
sid: sid || 0
});
this.websitehomeGet()
this.websitehomeGet();
this.innerAudioContext = wx.createInnerAudioContext(); // 当前页面唯一的一个音频容器
},
/**
......@@ -479,4 +482,141 @@ Page({
})
},
voiceIntervalPlay(value) { // 初始化录音的状态
let voiceInterval = setInterval(() => {
let audioStorage = this.data.audioStorage;
let currentTime = ++audioStorage[value].currentTime;
this.setData({
audioStorage
})
if (currentTime >= this.data.audioStorage[value].duration) {
audioStorage[value].play = false;
audioStorage[value].currentTime = 0;
this.setData({
audioStorage
})
clearInterval(this.data.voiceInterval);
}
}, 1000);
this.setData({
voiceInterval
})
},
playvoice(e) {
const {
value,
duration
} = e.detail;
const that = this;
this.innerAudioContext.src = audioorigin(value);
this.innerAudioContext.obeyMuteSwitch = false;
that.resetAudiosPlayStatus();
clearInterval(that.data.voiceInterval);
let audioStorage = that.data.audioStorage;
if (!audioStorage[value]) {
audioStorage[value] = {
play: true,
currentTime: 0,
duration
}
} else {
if (audioStorage[value].currentTime == audioStorage[value].duration) {
audioStorage[value].currentTime = 0;
audioStorage[value].play = true;
} else {
audioStorage[value].play = true;
}
}
this.innerAudioContext.seek(audioStorage[value].currentTime)
this.innerAudioContext.play();
that.voiceIntervalPlay(value);
that.setData({
audioStorage,
})
this.innerAudioContext.onCanplay(function (e) {
console.log('可以播放')
})
},
pausevoice(e) {
const {
value
} = e.detail;
let audioStorage = this.data.audioStorage;
audioStorage[value].play = false;
this.setData({
audioStorage,
})
this.innerAudioContext.pause();
clearInterval(this.data.voiceInterval);
},
voiceslide(e) {
const {
value,
slide,
duration
} = e.detail;
let audioStorage = this.data.audioStorage;
if (!audioStorage[value]) {
audioStorage[value] = {
play: false,
currentTime: slide,
duration
}
} else {
audioStorage[value].currentTime = slide;
}
this.innerAudioContext.seek(slide);
this.setData({
audioStorage,
})
},
slidestart(e) {
const {
value,
slide
} = e.detail;
let audioStorage = this.data.audioStorage;
if (audioStorage[value] && audioStorage[value].play) { // 如果当前是播放状态 则先暂停音乐盒计时器 播放按钮状态不需要改
this.innerAudioContext.pause();
clearInterval(this.data.voiceInterval);
} else { // 如果当前不是播放状态 则该干嘛干嘛
}
},
slideend(e) {
const {
value,
slide
} = e.detail;
let audioStorage = this.data.audioStorage;
if (audioStorage[value] && audioStorage[value].play) { // 如果当前是播放状态 则启用定时器 播放按钮状态不需要改
// clearInterval(this.data.voiceInterval);
this.innerAudioContext.play();
this.voiceIntervalPlay(value);
} else { // 如果当前不是播放状态 则该干嘛干嘛
}
},
resetAudiosPlayStatus() { // 点击一个录音的时候把其他的录音状态改成暂停状态
let audioStorage = this.data.audioStorage;
Object.keys(audioStorage).forEach((key) => {
audioStorage[key].play = false
});
this.setData({
audioStorage,
})
},
delvoice(e) {
const {
value
} = e.detail;
let audioStorage = this.data.audioStorage;
if (audioStorage[value] && audioStorage[value].play) { // 如果当前是播放状态 删除录音的操作要把录音销毁掉
delete audioStorage[value]
this.innerAudioContext.destroy();
clearInterval(this.data.voiceInterval);
}
this.setData({
audioStorage,
})
},
})
\ No newline at end of file
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