当前位置: 首页 > 工具软件 > amrnb > 使用案例 >

amrnb.min.js 播放本地amr音频文件

云季萌
2023-12-01

1.准备插件:amrnb.min.js,pcmdata.min.js

 下载地址:https://github.com/jpemartins/amr.js/blob/master/dist/amrnb.min.js

   https://github.com/jpemartins/amr.js/blob/master/public/js/lib/pcmdata.min.js


2.html代码

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Audio Example</title>
</head>
<body>
	<span class="bold">amr文件(*.amr):</span>
	<input type="file" id="file" name="file" />
</body>
<script src="/amr_player/amrnb.min.js"></script>
<script src="/amr_player/pcmdata.min.js"></script>
<script src="/amr_player/enter.js"></script>
<script>
	document.getElementById('file').addEventListener('change', function(evt) {
		var f = evt.target.files[0]; // File Object
		handleFileSelect(f);
	}, false);
</script>
</html>
3.enter.js
 
function handleFileSelect(f, isTypedArray) {
	var reader = new FileReader();// 文件阅读器
	reader.onload = (function(file) {
		return function(e) {
			var extension = file.name.split(".")[1];
			if (extension === "amr") {
				var samples = new AMR({
					benchmark : true
				}).decode(e.target.result);
				AMR.util.play(samples);
			}
		}
	})(f);

	if (!!isTypedArray) {
		reader.readAsArrayBuffer(f);
		return;
	}
	reader.readAsBinaryString(f);
}


 类似资料: