Commit a5c28704 authored by wangxuelai's avatar wangxuelai

'录音播放B端上线'

parent 20802a30
......@@ -136,7 +136,6 @@ App({
},
canEnterSystem (path) {
const visitor = LocalStorage.getItem('visitor');
console.log(visitor, 'visitor');
// 新版本通知
// if (LocalStorage.getItem('versionNotice') != 1 && path != 'src/pages/versionnotice/index') {
// wx.redirectTo({
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -216,8 +216,8 @@
audioStorage="{{audioStorage}}"
bind:slidestart="slidestart"
bind:slideend="slideend"
bind:delvoice="delvoice"
bind:playvideo="playvideo"
bind:delvoice="delvoice"
withmask="{{showWarn}}">
</sjd-media-editor>
<!-- bind:posterloaderr="posterloaderr" -->
......
This diff is collapsed.
This diff is collapsed.
......@@ -50,9 +50,9 @@
activeColor="#65B8F4"
block-color="#65B8F4"
color="#00000033"
max="{{audioStorage[item.value] && audioStorage[item.value].duration || 0}}"
max="{{item.duration}}"
value="{{audioStorage[item.value] && audioStorage[item.value].currentTime || 0}}"
/>
/>
<view class="total-time" >
{{filter.voiceTimeFormat(item.duration)}}
</view>
......
......@@ -2,32 +2,50 @@ import {
audioorigin,
} from '../../utilities/index';
module.exports = {
data: {
audioStorage: {},
actPalyaudioValue: ''
},
onLoad() {
// this.setData({
// actPalyaudioValue: '',
// audioStorage: {}
// })
this.innerAudioContext = wx.getBackgroundAudioManager(); // 当前页面唯一的一个音频容器
this.innerAudioContext.onWaiting((e) => {
const {
actPalyaudioValue,
audioStorage
} = this.data
if (audioStorage[actPalyaudioValue].isWaiting) {
return
}
} = this.data;
clearInterval(this.data.voiceInterval);
audioStorage[actPalyaudioValue].isWaiting = true
this.setData({
[`audioStorage.${actPalyaudioValue}`]: audioStorage[actPalyaudioValue],
})
setTimeout((e) => {
this.data.audioStorage[actPalyaudioValue].isWaiting = false;
this.setData({
[`audioStorage.${actPalyaudioValue}`]: audioStorage[actPalyaudioValue],
})
}, 5000)
})
this.innerAudioContext.onCanplay((e) => {
})
this.innerAudioContext.onError((e) => {
const {
actPalyaudioValue,
audioStorage
} = this.data;
audioStorage[actPalyaudioValue].isWaiting = false;
audioStorage[actPalyaudioValue].play = false;
wx.showToast({
title: '音频播放出错啦',
icon: 'none',
duration: 2000
})
this.setData({
audioStorage,
})
})
this.innerAudioContext.onTimeUpdate((e) => {
const {
actPalyaudioValue,
audioStorage
} = this.data
} = this.data;
if (audioStorage[actPalyaudioValue].isWaiting) {
//this.innerAudioContext.seek(audioStorage[actPalyaudioValue].currentTime || 0)
clearInterval(this.data.voiceInterval);
......@@ -39,7 +57,7 @@ module.exports = {
}
})
},
onHide: function() {
onHide: function() {
this.innerAudioContext.pause();
this.resetAudiosPlayStatus()
clearInterval(this.data.voiceInterval);
......@@ -74,15 +92,13 @@ module.exports = {
playvoice(e) {
const value = e.detail.value || e.currentTarget.dataset.value || 0;
const duration = e.detail.duration || e.currentTarget.dataset.duration || 0;
const that = this;
let audioStorage = that.data.audioStorage;
let audioStorage = this.data.audioStorage;
this.innerAudioContext.src = audioorigin(value);
this.innerAudioContext.title = '正在播放';
this.innerAudioContext.startTime = audioStorage[value] ? audioStorage[value].currentTime : 0;
this.innerAudioContext.obeyMuteSwitch = false;
that.resetAudiosPlayStatus();
clearInterval(that.data.voiceInterval);
this.resetAudiosPlayStatus();
clearInterval(this.data.voiceInterval);
if (!audioStorage[value]) {
audioStorage[value] = {
play: true,
......@@ -91,7 +107,7 @@ module.exports = {
isWaiting: true
}
} else {
audioStorage[value].isWaiting = true
audioStorage[value].isWaiting = false;
if (audioStorage[value].currentTime == audioStorage[value].duration) {
audioStorage[value].currentTime = 0;
audioStorage[value].play = true;
......@@ -99,25 +115,9 @@ module.exports = {
audioStorage[value].play = true;
}
}
this.voiceIntervalPlay(value);
this.innerAudioContext.play();
this.innerAudioContext.onError((e) => {
const {
actPalyaudioValue,
audioStorage
} = this.data
audioStorage[actPalyaudioValue].isWaiting = false;
audioStorage[actPalyaudioValue].play = false;
wx.showToast({
title: '音频播放出错啦',
icon: 'none',
duration: 2000
})
that.setData({
audioStorage,
})
})
that.setData({
this.setData({
audioStorage,
actPalyaudioValue: value
})
......@@ -141,13 +141,24 @@ module.exports = {
audioStorage[value] = {
play: false,
currentTime: slide,
duration
duration,
isWaiting: false
}
} else {
audioStorage[value].currentTime = slide;
audioStorage[value].isWaiting = true;
audioStorage[value].isWaiting = false;
}
if (slide >= audioStorage[value].duration) {
audioStorage[value].currentTime = 0;
audioStorage[value].play = false;
audioStorage[value].innerAudioContext.pause();
clearInterval(this.data.voiceInterval);
// audioStorage[value].innerAudioContext.seek(0);
}
if (audioStorage[value] && audioStorage[value].play) {
this.innerAudioContext.seek(slide);
// this.innerAudioContext.startTime = slide;
}
this.innerAudioContext.seek(slide);
this.setData({
audioStorage,
})
......@@ -158,24 +169,30 @@ module.exports = {
let audioStorage = this.data.audioStorage;
if (audioStorage[value] && audioStorage[value].play) { // 如果当前是播放状态 则先暂停音乐盒计时器 播放按钮状态不需要改
this.innerAudioContext.pause();
audioStorage[value].play = false;
clearInterval(this.data.voiceInterval);
} else { // 如果当前不是播放状态 则该干嘛干嘛
}
this.setData({
actPalyaudioValue: value,
audioStorage,
})
},
slideend(e) {
const value = e.detail.value || e.currentTarget.dataset.value || 0;
let audioStorage = this.data.audioStorage;
if (audioStorage[value] && audioStorage[value].play) { // 如果当前是播放状态 则启用定时器 播放按钮状态不需要改
// clearInterval(this.data.voiceInterval);
this.innerAudioContext.play();
this.voiceIntervalPlay(value);
// this.voiceIntervalPlay(value);
// this.innerAudioContext.play();
} else { // 如果当前不是播放状态 则该干嘛干嘛
}
},
resetAudiosPlayStatus() { // 点击一个录音的时候把其他的录音状态改成暂停状态
let audioStorage = this.data.audioStorage;
Object.keys(audioStorage).forEach((key) => {
audioStorage[key].play = false
audioStorage[key].play = false;
audioStorage[key].isWaiting = false;
});
this.setData({
audioStorage,
......
......@@ -489,6 +489,36 @@ function debounce(func, wait) {
}, wait);
}
}
function deepCopy (obj, cache = []) {
// typeof [] => 'object'
// typeof {} => 'object'
if (obj === null || typeof obj !== 'object') {
return obj
}
// 如果传入的对象与缓存的相等, 则递归结束, 这样防止循环
/**
* 类似下面这种
* var a = {b:1}
* a.c = a
* 资料: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value
*/
const hit = cache.filter(c => c.original === obj)[0]
if (hit) {
return hit.copy
}
const copy = Array.isArray(obj) ? [] : {}
// 将copy首先放入cache, 因为我们需要在递归deepCopy的时候引用它
cache.push({
original: obj,
copy
})
Object.keys(obj).forEach(key => {
copy[key] = deepCopy(obj[key], cache)
})
return copy
}
export {
encode,
decode,
......@@ -516,5 +546,6 @@ export {
copyContent,
debounce,
mediaimagify,
transformOssVideofy
transformOssVideofy,
deepCopy,
}
\ 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