uni-app 音频播放错误

uni-app 音频播放错误

类别 信息
产品分类 uniapp/App
PC开发环境 Windows
PC开发环境版本 win10
HBuilderX类型 正式
HBuilderX版本 4.57
手机系统 Android
手机系统版本 Android 7.1.1
手机厂商 商米收银机
手机机型 D1s
页面类型 nvue
Vue版本 vue3
打包方式 云端
项目创建方式 HBuilderX

示例代码:

let self = this
isPlayAudio = true
const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.src = config.tongclmall_url + '/' + filePath; // 设置音频源路径
innerAudioContext.autoplay = true; // 自动播放
// 事件监听
innerAudioContext.onPlay(() => {
console.log('音频开始播放');
});
innerAudioContext.onEnded((err) => {
queue_notice_way = queue_notice_way - 1
if (queue_notice_way > 0) {
self.createAudioPlayer(filePath)
} else {
self.destroyAudioPlayer()
isPlayAudio = false
}
});
innerAudioContext.onError((err) => {
console.error('播放错误:', err);
isPlayAudio = false
self.destroyAudioPlayer()
});

操作步骤:

音频播放错误

预期结果:

音频播放错误

实际结果:

音频播放错误

bug描述:

音频播放错误提示 -99


更多关于uni-app 音频播放错误的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于uni-app 音频播放错误的实战教程也可以访问 https://www.itying.com/category-93-b0.html


针对音频播放错误-99的问题,这个错误码通常表示音频文件加载失败。以下是可能的原因和解决方案:

  1. 文件路径问题:
  • 检查config.tongclmall_url + '/' + filePath拼接后的完整URL是否正确
  • 确保音频文件确实存在于服务器上
  • 尝试直接在浏览器中访问该URL看是否能播放
  1. 音频格式兼容性问题:
  • Android设备对音频格式支持有限,建议使用MP3格式
  • 检查音频文件是否损坏
  1. 网络问题:
  • 确保设备网络连接正常
  • 如果是HTTPS地址,检查证书是否有效
  1. 代码改进建议:
// 先验证URL
const audioUrl = config.tongclmall_url + '/' + filePath;
console.log('尝试播放音频:', audioUrl);

// 创建前先销毁旧的实例
if(innerAudioContext){
    innerAudioContext.destroy();
}

const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.src = audioUrl;

// 增加加载事件监听
innerAudioContext.onCanplay(() => {
    console.log('音频可以播放');
    innerAudioContext.play();
});
回到顶部