AMR 播放器,录音机,转换器 纯前端解码、播放、录音、编码 AMR 音频,无须服务器支持, 基于BenzAMRRecorder.js 说明: demo.html -- 原文demo demo-en.html -- 原文demo英文版 test_playUrl.html -- 测试播放Url 注: 以上html不能在资源管理器右键浏览器打开测试 需要在idea里面打开谷歌浏览器调试,或放入tomcat容器运行调试 因为js代码里的url转换数据用到XMLHttpRequest 直接用浏览器打开不能加载成功,会导致无法播放! test_playBase64.html --测试播放Base64Amr(可以在资源管理器右键浏览器打开测试) test_mp3ToAmr.html --测试mp3转换amr(可以在资源管理器右键浏览器打开测试)
页面展示:
js转换方法
function convert(){
if (curLoadMp3File == null) {
alert("请先加载本地mp3");
return;
}
convert2Amr.setAttribute('disabled', true);
curPlayAmrObj = new BenzAMRRecorder();
curPlayAmrObj.initWithBlob(curLoadMp3File).then(function () {
var playAmr = E('#playAmr');
playAmr.removeAttribute('disabled');
amrFromBlob = curPlayAmrObj.getBlob();
amrDownloadFile.href = window.URL.createObjectURL(amrFromBlob);
amrDownloadFile.innerHTML = "下载【" + downloadFileName + "】";
});
}
js加载base64方法
var myBlob=base64ToBlob(amrBase64Txt, "audio/amr");
curPlayAmrObj = new BenzAMRRecorder();
var duration = document.getElementById("amr-duration");
var progressCtrl = document.getElementById("amr-progress");
var stopBtn = document.getElementById("stop1");
curPlayAmrObj.initWithBlob(myBlob).then(function () {
stopBtn.removeAttribute('disabled');
progressCtrl.removeAttribute('disabled');
progressCtrl.setAttribute('max', curPlayAmrObj.getDuration());
duration.innerHTML = curPlayAmrObj.getDuration().toFixed(2) + '\'';
curPlayAmrObj.play();
taskTimer1 = setInterval(alterProgress, 10);
});
js加载url方法
curPlayAmrObj = new BenzAMRRecorder();
var duration = document.getElementById("amr-duration");
var progressCtrl = document.getElementById("amr-progress");
var stopBtn = document.getElementById("stop1");
curPlayAmrObj.initWithUrl(amrUrl).then(function () {
stopBtn.removeAttribute('disabled');
progressCtrl.removeAttribute('disabled');
progressCtrl.setAttribute('max', curPlayAmrObj.getDuration());
duration.innerHTML = curPlayAmrObj.getDuration().toFixed(2) + '\'';
curPlayAmrObj.play();
taskTimer1 = setInterval(alterProgress, 10);
});
Demo下载地址 https://download.csdn.net/download/tianbbs2008/23266292