Commit a5c28704 authored by wangxuelai's avatar wangxuelai

'录音播放B端上线'

parent 20802a30
...@@ -136,7 +136,6 @@ App({ ...@@ -136,7 +136,6 @@ App({
}, },
canEnterSystem (path) { canEnterSystem (path) {
const visitor = LocalStorage.getItem('visitor'); const visitor = LocalStorage.getItem('visitor');
console.log(visitor, 'visitor');
// 新版本通知 // 新版本通知
// if (LocalStorage.getItem('versionNotice') != 1 && path != 'src/pages/versionnotice/index') { // if (LocalStorage.getItem('versionNotice') != 1 && path != 'src/pages/versionnotice/index') {
// wx.redirectTo({ // 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 { ...@@ -15,13 +15,15 @@ import {
audioorigin, audioorigin,
formatDate, formatDate,
getDateInfo, getDateInfo,
LocalStorage LocalStorage,
deepCopy
} from '../../../utilities/index.js'; } from '../../../utilities/index.js';
import { import {
erpClassListGet, erpClassListGet,
} from '../../../service/business/common.js'; } from '../../../service/business/common.js';
var app = getApp(); var app = getApp();
Page({ Page({
// mixins: [deepCopy(require('../../../mixins/myMins/audioCallback'))],
data: { data: {
maxLength: 500, maxLength: 500,
maxImgCount: 9, maxImgCount: 9,
...@@ -118,35 +120,24 @@ Page({ ...@@ -118,35 +120,24 @@ Page({
onLoad: function(options) { // Do some initialize when page load. onLoad: function(options) { // Do some initialize when page load.
const that = this; const that = this;
this.innerAudioContext = wx.createInnerAudioContext(); // 当前页面唯一的一个音频容器 this.innerAudioContext = wx.createInnerAudioContext(); // 当前页面唯一的一个音频容器
this.innerAudioContext.onWaiting((e)=>{ this.innerAudioContext.onWaiting((e) => {
const { actPalyaudioValue, audioStorage} = this.data const {
if(audioStorage[actPalyaudioValue].isWaiting){ actPalyaudioValue,
return audioStorage
} } = this.data;
clearInterval(this.data.voiceInterval);
audioStorage[actPalyaudioValue].isWaiting = true audioStorage[actPalyaudioValue].isWaiting = true
that.setData({
audioStorage,
})
setTimeout((e)=>{
this.data.audioStorage[actPalyaudioValue].isWaiting = false;
this.setData({ 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)=>{ this.innerAudioContext.onError((e) => {
const { actPalyaudioValue, audioStorage} = this.data const {
actPalyaudioValue,
audioStorage
} = this.data;
audioStorage[actPalyaudioValue].isWaiting = false; audioStorage[actPalyaudioValue].isWaiting = false;
audioStorage[actPalyaudioValue].play = false; audioStorage[actPalyaudioValue].play = false;
wx.showToast({ wx.showToast({
...@@ -154,10 +145,26 @@ Page({ ...@@ -154,10 +145,26 @@ Page({
icon: 'none', icon: 'none',
duration: 2000 duration: 2000
}) })
that.setData({ this.setData({
audioStorage, 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 { const {
id, id,
tid, tid,
...@@ -198,11 +205,11 @@ Page({ ...@@ -198,11 +205,11 @@ Page({
}, },
onUnload: function() { // Do something when page close. onUnload: function() { // Do something when page close.
this.innerAudioContext.pause(); this.innerAudioContext.pause();
this.setData({ // this.setData({
audioStorage: { // audioStorage: {
} // }
}) // })
clearInterval(this.data.voiceInterval); clearInterval(this.data.voiceInterval);
}, },
...@@ -628,17 +635,15 @@ Page({ ...@@ -628,17 +635,15 @@ Page({
}) })
}, },
playvoice(e) { playvoice(e) {
const { const value = e.detail.value || e.currentTarget.dataset.value || 0;
value, const duration = e.detail.duration || e.currentTarget.dataset.duration || 0;
duration let audioStorage = this.data.audioStorage;
} = e.detail;
const that = this;
this.innerAudioContext.src = audioorigin(value); this.innerAudioContext.src = audioorigin(value);
this.innerAudioContext.title = '正在播放';
this.innerAudioContext.startTime = audioStorage[value] ? audioStorage[value].currentTime : 0;
this.innerAudioContext.obeyMuteSwitch = false; this.innerAudioContext.obeyMuteSwitch = false;
that.resetAudiosPlayStatus(); this.resetAudiosPlayStatus();
clearInterval(that.data.voiceInterval); clearInterval(this.data.voiceInterval);
let audioStorage = that.data.audioStorage;
if (!audioStorage[value]) { if (!audioStorage[value]) {
audioStorage[value] = { audioStorage[value] = {
play: true, play: true,
...@@ -647,7 +652,7 @@ Page({ ...@@ -647,7 +652,7 @@ Page({
isWaiting: true isWaiting: true
} }
} else { } else {
audioStorage[value].isWaiting = true audioStorage[value].isWaiting = false;
if (audioStorage[value].currentTime == audioStorage[value].duration) { if (audioStorage[value].currentTime == audioStorage[value].duration) {
audioStorage[value].currentTime = 0; audioStorage[value].currentTime = 0;
audioStorage[value].play = true; audioStorage[value].play = true;
...@@ -655,32 +660,15 @@ Page({ ...@@ -655,32 +660,15 @@ Page({
audioStorage[value].play = true; audioStorage[value].play = true;
} }
} }
this.voiceIntervalPlay(value);
// 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.innerAudioContext.play(); this.innerAudioContext.play();
this.setData({
//that.voiceIntervalPlay(value);
that.setData({
audioStorage, audioStorage,
actPalyaudioValue:value actPalyaudioValue: value
}) })
}, },
pausevoice(e) { pausevoice(e) {
const { const value = e.detail.value || e.currentTarget.dataset.value || 0;
value
} = e.detail;
let audioStorage = this.data.audioStorage; let audioStorage = this.data.audioStorage;
audioStorage[value].play = false; audioStorage[value].play = false;
this.setData({ this.setData({
...@@ -690,69 +678,77 @@ Page({ ...@@ -690,69 +678,77 @@ Page({
clearInterval(this.data.voiceInterval); clearInterval(this.data.voiceInterval);
}, },
voiceslide(e) { voiceslide(e) {
const { const value = e.detail.value || e.currentTarget.dataset.value || 0;
value, const duration = e.detail.duration || e.currentTarget.dataset.duration || 0;
slide, const slide = e.detail.slide || e.currentTarget.dataset.slide || 0;
duration
} = e.detail;
let audioStorage = this.data.audioStorage; let audioStorage = this.data.audioStorage;
if (!audioStorage[value]) { if (!audioStorage[value]) {
audioStorage[value] = { audioStorage[value] = {
play: false, play: false,
currentTime: slide, currentTime: slide,
duration duration,
isWaiting: false
} }
} else { } else {
audioStorage[value].currentTime = slide; 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.seek(slide);
// this.innerAudioContext.startTime = slide;
}
this.setData({ this.setData({
audioStorage, audioStorage,
}) })
}, },
slidestart(e) { slidestart(e) {
const { const value = e.detail.value || e.currentTarget.dataset.value || 0;
value, const slide = e.detail.slide || e.currentTarget.dataset.slide || 0;
slide
} = e.detail;
let audioStorage = this.data.audioStorage; let audioStorage = this.data.audioStorage;
if (audioStorage[value] && audioStorage[value].play) { // 如果当前是播放状态 则先暂停音乐盒计时器 播放按钮状态不需要改 if (audioStorage[value] && audioStorage[value].play) { // 如果当前是播放状态 则先暂停音乐盒计时器 播放按钮状态不需要改
this.innerAudioContext.pause(); this.innerAudioContext.pause();
audioStorage[value].play = false;
clearInterval(this.data.voiceInterval); clearInterval(this.data.voiceInterval);
} else { // 如果当前不是播放状态 则该干嘛干嘛 } else { // 如果当前不是播放状态 则该干嘛干嘛
} }
this.setData({
actPalyaudioValue: value,
audioStorage,
})
}, },
slideend(e) { slideend(e) {
const { const value = e.detail.value || e.currentTarget.dataset.value || 0;
value,
slide
} = e.detail;
let audioStorage = this.data.audioStorage; let audioStorage = this.data.audioStorage;
if (audioStorage[value] && audioStorage[value].play) { // 如果当前是播放状态 则启用定时器 播放按钮状态不需要改 if (audioStorage[value] && audioStorage[value].play) { // 如果当前是播放状态 则启用定时器 播放按钮状态不需要改
// clearInterval(this.data.voiceInterval); // clearInterval(this.data.voiceInterval);
this.innerAudioContext.play(); // this.voiceIntervalPlay(value);
this.voiceIntervalPlay(value); // this.innerAudioContext.play();
} else { // 如果当前不是播放状态 则该干嘛干嘛 } else { // 如果当前不是播放状态 则该干嘛干嘛
} }
}, },
resetAudiosPlayStatus() { // 点击一个录音的时候把其他的录音状态改成暂停状态 resetAudiosPlayStatus() { // 点击一个录音的时候把其他的录音状态改成暂停状态
let audioStorage = this.data.audioStorage; let audioStorage = this.data.audioStorage;
Object.keys(audioStorage).forEach((key) => { Object.keys(audioStorage).forEach((key) => {
audioStorage[key].play = false audioStorage[key].play = false;
audioStorage[key].isWaiting = false;
}); });
this.setData({ this.setData({
audioStorage, audioStorage,
}) })
}, },
delvoice(e) { delvoice(e) {
const { const value = e.detail.value || e.currentTarget.dataset.value || 0;
value
} = e.detail;
let audioStorage = this.data.audioStorage; let audioStorage = this.data.audioStorage;
if (audioStorage[value] && audioStorage[value].play) { // 如果当前是播放状态 删除录音的操作要把录音销毁掉 if (audioStorage[value] && audioStorage[value].play) { // 如果当前是播放状态 删除录音的操作要把录音销毁掉
delete audioStorage[value] delete audioStorage[value]
this.innerAudioContext.pause(); this.innerAudioContext.destroy();
clearInterval(this.data.voiceInterval); clearInterval(this.data.voiceInterval);
} }
this.setData({ this.setData({
......
This diff is collapsed.
...@@ -216,8 +216,8 @@ ...@@ -216,8 +216,8 @@
audioStorage="{{audioStorage}}" audioStorage="{{audioStorage}}"
bind:slidestart="slidestart" bind:slidestart="slidestart"
bind:slideend="slideend" bind:slideend="slideend"
bind:delvoice="delvoice"
bind:playvideo="playvideo" bind:playvideo="playvideo"
bind:delvoice="delvoice"
withmask="{{showWarn}}"> withmask="{{showWarn}}">
</sjd-media-editor> </sjd-media-editor>
<!-- bind:posterloaderr="posterloaderr" --> <!-- bind:posterloaderr="posterloaderr" -->
......
This diff is collapsed.
This diff is collapsed.
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
activeColor="#65B8F4" activeColor="#65B8F4"
block-color="#65B8F4" block-color="#65B8F4"
color="#00000033" color="#00000033"
max="{{audioStorage[item.value] && audioStorage[item.value].duration || 0}}" max="{{item.duration}}"
value="{{audioStorage[item.value] && audioStorage[item.value].currentTime || 0}}" value="{{audioStorage[item.value] && audioStorage[item.value].currentTime || 0}}"
/> />
<view class="total-time" > <view class="total-time" >
......
This diff is collapsed.
...@@ -489,6 +489,36 @@ function debounce(func, wait) { ...@@ -489,6 +489,36 @@ function debounce(func, wait) {
}, 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 { export {
encode, encode,
decode, decode,
...@@ -516,5 +546,6 @@ export { ...@@ -516,5 +546,6 @@ export {
copyContent, copyContent,
debounce, debounce,
mediaimagify, 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