uni-app createInnerAudioContext播放wav Bug

uni-app createInnerAudioContext播放wav Bug

示例代码:

const innerAudioContext = uni.createInnerAudioContext();  
innerAudioContext.autoplay = true;  

innerAudioContext.src = './static/1.wav';  
innerAudioContext.onPlay(() => {  
    console.log('开始播放');  
});  

innerAudioContext.onError((res) => {  
    console.log(res.errMsg);  
    console.log(res.errCode);  
});

操作步骤:

const innerAudioContext = uni.createInnerAudioContext();  
innerAudioContext.autoplay = true;  

innerAudioContext.src = './static/1.wav';  
innerAudioContext.onPlay(() => {  
    console.log('开始播放');  
});  

innerAudioContext.onError((res) => {  
    console.log(res.errMsg);  
    console.log(res.errCode);  
});

预期结果:

正常播放

实际结果:

const innerAudioContext = uni.createInnerAudioContext();  
innerAudioContext.autoplay = true;  

innerAudioContext.src = './static/1.wav';  
innerAudioContext.onPlay(() => {  
    console.log('开始播放');  
});  

innerAudioContext.onError((res) => {  
    console.log(res.errMsg);  
    console.log(res.errCode);  
});

bug描述:

20:27:35.142 MediaError at pages/index/index.vue:45
20:27:35.162 [Number] -5 at pages/index/index.vue:46

bug描述附件


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

10 回复

管理员来瞧一下

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


请提供测试 wav 音频文件

附件中 test.rar

再传一个

见第一贴,附件

提供的测试文件的位深度位是 4,不在 Android 系统的默认支持范围,Android 对 PCM/WAVE 支持范围是 8 位和 16 位线性 PCM(比特率最高可达到硬件上限)。以 8000、16000 和 44100 Hz 录制原始 PCM 所需的采样率。 参考文档 https://developer.android.google.cn/guide/topics/media/media-formats
换个文件试试

转换了格式,还是不行

转换了好几种格式,都不行,请管理员看一下,谢谢

这是一个已知的音频格式兼容性问题。createInnerAudioContext 在不同平台对 WAV 格式的支持存在差异,特别是在 iOS 和部分 Android 设备上。

错误码 -5 通常表示媒体格式不支持。虽然 WAV 是标准格式,但不同设备解码器对 WAV 编码参数(如采样率、位深度、编码方式)的要求不同。

建议的解决方案:

  1. 转换音频格式:将 WAV 文件转换为 MP3 或 AAC 格式,这两种格式在移动端有更好的兼容性。可以使用 FFmpeg 或在线转换工具。

  2. 检查 WAV 文件参数:如果必须使用 WAV,确保音频参数为:

    • 采样率:44100Hz 或 48000Hz
    • 位深度:16bit
    • 编码:PCM 编码
  3. 使用相对路径或网络路径:尝试将音频文件放在服务器上,使用网络 URL:

    innerAudioContext.src = 'https://your-domain.com/static/1.mp3';
    
  4. 添加格式检测

    innerAudioContext.onCanplay(() => {
      console.log('可以播放');
    });
回到顶部