-
后端把音频文件转为Base64音频流
<?php
header( "Content-type: audio/mp3");
$file='audio.mp3';
$content=file_get_contents($file);
echo base64_decode($content);//输出流
-
HTML audio 播放Base64音频流
页面元素:
<audio controls="controls" autoplay />
请求接口拿数据,并刷新控件,播放音频:
ceshi({}).then(res=>{
document.getElementsByTagName("audio")[0].setAttribute("src", "data:audio/mp3;base64,"+res);
})
参考: