import Vue from 'vue'; import Vuex from 'vuex'; Vue.use(Vuex) export default new Vuex.Store({ state: { bgAudioMannager: null, // 背景音频播放对象 isBgPlay: false, // 是否后台播放 messageObj: {}, // }, mutations: { // 日报详情 setMessageObj(state, obj) { state.messageObj = obj }, createAudio(state) { state.bgAudioMannager = uni.getBackgroundAudioManager(); }, setSeekAudio(state, t) { state.bgAudioMannager.seek(t) }, // 加载音频监听方法 initAudioMethod(state, obj) { state.bgAudioMannager.onCanplay(() => { state.bgAudioMannager.currentTime = obj.currentTime }); state.bgAudioMannager.onStop(() => { console.log('停止播放'); }); state.bgAudioMannager.onPause(() => { console.log('暂停播放'); }); state.bgAudioMannager.onEnded(() => { //初始化 需要的参数 console.log('自然播放结束事件'); }); state.bgAudioMannager.onError((res) => { console.log(res.errMsg); console.log(res.errCode); }); }, // 停止全局音频播放 stopAduio(state) { if (state.bgAudioMannager != null) { if (state.bgAudioMannager.src != '') { state.bgAudioMannager.src = '' } } }, // 设置播放状态 setIsBgPlay(state, value) { state.isBgPlay = value } }, })