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.
 
 
 

54 lines
1.1 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. },
  8. mutations: {
  9. createAudio(state) {
  10. state.bgAudioMannager = uni.getBackgroundAudioManager();
  11. },
  12. setSeekAudio(state, t) {
  13. state.bgAudioMannager.seek(t)
  14. },
  15. // 加载音频监听方法
  16. initAudioMethod (state, obj) {
  17. state.bgAudioMannager.onCanplay(() => {
  18. state.bgAudioMannager.currentTime = obj.currentTime
  19. });
  20. state.bgAudioMannager.onStop(() => {
  21. console.log('停止播放');
  22. });
  23. state.bgAudioMannager.onPause(() => {
  24. console.log('暂停播放');
  25. });
  26. state.bgAudioMannager.onEnded(() => {
  27. //初始化 需要的参数
  28. console.log('自然播放结束事件');
  29. });
  30. state.bgAudioMannager.onError((res) => {
  31. console.log(res.errMsg);
  32. console.log(res.errCode);
  33. });
  34. },
  35. // 停止全局音频播放
  36. stopAduio(state) {
  37. state.bgAudioMannager && state.bgAudioMannager.pause()
  38. if (state.bgAudioMannager && state.bgAudioMannager.src) {
  39. state.bgAudioMannager.src = ''
  40. }
  41. },
  42. },
  43. action: {
  44. }
  45. })