remoteUrl传入值
fetch(remoteUrl).then(response => response.blob())
.then(blob => {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
const base64Data = reader.result.split(',')[1];
amrToWav(base64Data);
};
}).catch(error => console.error('Error fetching remote file:', error));
1. togglePlay(index) 函数:根据 audioPlayers 数组中是否存在特定索引的音频播放器来切换播放状态。如果不存在,则调用 playAudio(index) 播放音频,否则根据当前播放状态执行暂停或继续播放操作。
2. playAudio(index) 函数:根据提供的音频URL获取音频数据,并将其转换为Base64编码的Blob对象,然后解码为PCM格式并调用 playPcm(samples, index) 进行播放。
3. base64ToBlob 函数:将Base64编码的数据转换为Blob对象。
4. readBlob 函数:读取Blob对象并将其转换为Uint8Array格式。
5. playAmrArray(array, index) 函数:解码AMR格式音频数据为PCM格式,并调用 playPcm(samples, index) 进行播放。
6. playPcm(samples, index) 函数:创建音频上下文对象,创建音频缓冲区并播放音频。
7. pauseAudio(index) 函数:暂停指定索引的音频播放器。
8. resumeAudio(index) 函数:继续播放指定索引的音频。
9. recoil(index) 函数:实现倒退功能,记录上一次倒退的时间点,根据当前时间和上一次倒退时间计算倒退时间,并播放音频。在播放前暂停之前的音频。