AI销管
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

59 lines
1.2 KiB

  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. Vue.use(Vuex)
  4. export default new Vuex.Store({
  5. state: {
  6. bgAudioMannager: null, // 背景音频播放对象
  7. isBgPlay: false, // 是否后台播放
  8. },
  9. mutations: {
  10. createAudio(state) {
  11. state.bgAudioMannager = uni.getBackgroundAudioManager();
  12. },
  13. setSeekAudio(state, t) {
  14. state.bgAudioMannager.seek(t)
  15. },
  16. // 加载音频监听方法
  17. initAudioMethod(state, obj) {
  18. state.bgAudioMannager.onCanplay(() => {
  19. state.bgAudioMannager.currentTime = obj.currentTime
  20. });
  21. state.bgAudioMannager.onStop(() => {
  22. console.log('停止播放');
  23. });
  24. state.bgAudioMannager.onPause(() => {
  25. console.log('暂停播放');
  26. });
  27. state.bgAudioMannager.onEnded(() => {
  28. //初始化 需要的参数
  29. console.log('自然播放结束事件');
  30. });
  31. state.bgAudioMannager.onError((res) => {
  32. console.log(res.errMsg);
  33. console.log(res.errCode);
  34. });
  35. },
  36. // 停止全局音频播放
  37. stopAduio(state) {
  38. if (state.bgAudioMannager != null) {
  39. if (state.bgAudioMannager.src != '') {
  40. state.bgAudioMannager.src = ''
  41. }
  42. }
  43. },
  44. // 设置播放状态
  45. setIsBgPlay(state, value) {
  46. state.isBgPlay = value
  47. }
  48. },
  49. })