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.
......@@ -15,13 +15,15 @@ import {
audioorigin,
formatDate,
getDateInfo,
LocalStorage
LocalStorage,
deepCopy
} from '../../../utilities/index.js';
import {
erpClassListGet,
} from '../../../service/business/common.js';
var app = getApp();
Page({
// mixins: [deepCopy(require('../../../mixins/myMins/audioCallback'))],
data: {
maxLength: 500,
maxImgCount: 9,
......@@ -118,35 +120,24 @@ Page({
onLoad: function(options) { // Do some initialize when page load.
const that = this;
this.innerAudioContext = wx.createInnerAudioContext(); // 当前页面唯一的一个音频容器
this.innerAudioContext.onWaiting((e)=>{
const { actPalyaudioValue, audioStorage} = this.data
if(audioStorage[actPalyaudioValue].isWaiting){
return
}
this.innerAudioContext.onWaiting((e) => {
const {
actPalyaudioValue,
audioStorage
} = this.data;
clearInterval(this.data.voiceInterval);
audioStorage[actPalyaudioValue].isWaiting = true
that.setData({
audioStorage,
})
setTimeout((e)=>{
this.data.audioStorage[actPalyaudioValue].isWaiting = false;
this.setData({
audioStorage: this.data.audioStorage
[`audioStorage.${actPalyaudioValue}`]: audioStorage[actPalyaudioValue],
})
},5000)
})
this.innerAudioContext.onTimeUpdate((e) => {
const { actPalyaudioValue, audioStorage} = this.data
if (audioStorage[actPalyaudioValue].isWaiting) {
clearInterval(that.data.voiceInterval);
that.voiceIntervalPlay(actPalyaudioValue);
audioStorage[actPalyaudioValue].isWaiting = false
that.setData({
audioStorage,
})
}
this.innerAudioContext.onCanplay((e) => {
})
this.innerAudioContext.onError((e)=>{
const { actPalyaudioValue, audioStorage} = this.data
this.innerAudioContext.onError((e) => {
const {
actPalyaudioValue,
audioStorage
} = this.data;
audioStorage[actPalyaudioValue].isWaiting = false;
audioStorage[actPalyaudioValue].play = false;
wx.showToast({
......@@ -154,10 +145,26 @@ Page({
icon: 'none',
duration: 2000
})
that.setData({
this.setData({
audioStorage,
})
});
})
this.innerAudioContext.onTimeUpdate((e) => {
console.log(this.data, 'this.data');
const {
actPalyaudioValue,
audioStorage
} = this.data;
if (audioStorage[actPalyaudioValue].isWaiting) {
//this.innerAudioContext.seek(audioStorage[actPalyaudioValue].currentTime || 0)
clearInterval(this.data.voiceInterval);
this.voiceIntervalPlay(actPalyaudioValue);
audioStorage[actPalyaudioValue].isWaiting = false
this.setData({
[`audioStorage.${actPalyaudioValue}`]: audioStorage[actPalyaudioValue],
})
}
})
const {
id,
tid,
......@@ -198,11 +205,11 @@ Page({
},
onUnload: function() { // Do something when page close.
this.innerAudioContext.pause();
this.setData({
audioStorage: {
// this.setData({
// audioStorage: {
}
})
// }
// })
clearInterval(this.data.voiceInterval);
},
......@@ -628,17 +635,15 @@ Page({
})
},
playvoice(e) {
const {
value,
duration
} = e.detail;
const that = this;
const value = e.detail.value || e.currentTarget.dataset.value || 0;
const duration = e.detail.duration || e.currentTarget.dataset.duration || 0;
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);
let audioStorage = that.data.audioStorage;
this.resetAudiosPlayStatus();
clearInterval(this.data.voiceInterval);
if (!audioStorage[value]) {
audioStorage[value] = {
play: true,
......@@ -647,7 +652,7 @@ Page({
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;
......@@ -655,32 +660,15 @@ Page({
audioStorage[value].play = true;
}
}
// this.innerAudioContext.onCanplay((e)=>{
// const { actPalyaudioValue, audioStorage} = this.data
// if (audioStorage[actPalyaudioValue].isWaiting) {
// clearInterval(that.data.voiceInterval);
// that.voiceIntervalPlay(actPalyaudioValue);
// audioStorage[actPalyaudioValue].isWaiting = false
// that.setData({
// audioStorage,
// })
// }
// })
console.log(audioStorage[value].currentTime, 'audioStorage[value].currentTime');
this.innerAudioContext.seek(audioStorage[value].currentTime)
this.voiceIntervalPlay(value);
this.innerAudioContext.play();
//that.voiceIntervalPlay(value);
that.setData({
this.setData({
audioStorage,
actPalyaudioValue:value
actPalyaudioValue: value
})
},
pausevoice(e) {
const {
value
} = e.detail;
const value = e.detail.value || e.currentTarget.dataset.value || 0;
let audioStorage = this.data.audioStorage;
audioStorage[value].play = false;
this.setData({
......@@ -690,69 +678,77 @@ Page({
clearInterval(this.data.voiceInterval);
},
voiceslide(e) {
const {
value,
slide,
duration
} = e.detail;
const value = e.detail.value || e.currentTarget.dataset.value || 0;
const duration = e.detail.duration || e.currentTarget.dataset.duration || 0;
const slide = e.detail.slide || e.currentTarget.dataset.slide || 0;
let audioStorage = this.data.audioStorage;
if (!audioStorage[value]) {
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.setData({
audioStorage,
})
},
slidestart(e) {
const {
value,
slide
} = e.detail;
const value = e.detail.value || e.currentTarget.dataset.value || 0;
const slide = e.detail.slide || e.currentTarget.dataset.slide || 0;
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,
slide
} = e.detail;
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,
})
},
delvoice(e) {
const {
value
} = e.detail;
const value = e.detail.value || e.currentTarget.dataset.value || 0;
let audioStorage = this.data.audioStorage;
if (audioStorage[value] && audioStorage[value].play) { // 如果当前是播放状态 删除录音的操作要把录音销毁掉
delete audioStorage[value]
this.innerAudioContext.pause();
this.innerAudioContext.destroy();
clearInterval(this.data.voiceInterval);
}
this.setData({
......
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,7 +50,7 @@
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" >
......
This diff is collapsed.
......@@ -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