13404089107
2025-05-23 e3a78db2a9b791284dfbc087f393ecca08de1ca1
H5/store/index.js
@@ -25,18 +25,63 @@
         }
         state.innerAudioContext = uni.createInnerAudioContext();
         state.innerAudioContext.autoplay = true;
         // state.innerAudioContext.src =
         //    'https://haitunyingyu.obs.cn-southwest-2.myhuaweicloud.com/admin/6660c5497ff34ee5b2bddaed01dd3880.wav';
         state.innerAudioContext.src = url
         // 设置音频格式为MPEG
         state.innerAudioContext.format = 'mpeg';
         state.innerAudioContext.src = url;
         // 显示音频信息
         // uni.showToast({
         //    title: '音频链接:' + url,
         //    icon: 'none',
         //    duration: 3000
         // });
         // 添加加载事件处理
         state.innerAudioContext.onCanplay(() => {
            console.log('音频可以播放了');
            uni.showToast({
               title: '音频已准备就绪',
               icon: 'none',
               duration: 2000
            });
         });
         state.innerAudioContext.onPlay(() => {
            state.playFlag = true;
            uni.showToast({
               title: '开始播放',
               icon: 'none',
               duration: 2000
            });
         });
         state.innerAudioContext.onError((res) => {
            // console.log('播放错误', res);
            console.log('播放错误', res);
            uni.showToast({
               title: '播放错误'+`${res}`,
               icon: 'none',
               duration: 3000
            });
            // 显示具体的错误信息
            // let errorMsg = '音频播放失败';
            // if (res.errMsg) {
            //    errorMsg += ':' + res.errMsg;
            // }
            // uni.showToast({
            //    title: errorMsg,
            //    icon: 'none',
            //    duration: 3000
            // });
            dispatch('stopPlaying')
         });
         state.innerAudioContext.onEnded((res) => {
            // console.log('播放自然结束', res);
            console.log('播放自然结束', res);
            uni.showToast({
               title: '播放结束',
               icon: 'none',
               duration: 2000
            });
            dispatch('stopPlaying')
         });
      },