js播放Amr音频_Mp3转Amr

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱喝咖啡的程序猿

写博不易且看且珍惜,打赏最给力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值