有没有人知道,如何使用JS将音频文件如何转换成base64格式的?
- 发布:2015-07-19 14:10
- 更新:2016-08-09 16:41
- 阅读:30484
最佳回复
通过读取文件 ,然后转码 .图片可以,其他文件一样可以的
// Read data from file
以www目录下audio/shake.wav为例:
plus.io.requestFileSystem(plus.io.PRIVATE_WWW,
function(fs) {
var rootEntry = fs.root;
var reader = null;
rootEntry.getFile('audio/shake.wav', {},
function(entry) {
entry.file(function(file) {
reader = new plus.io.FileReader();
reader.onloadend = function(e) {
plus.console.log("Read success");
// Get data
plus.console.log(e.target.result);
};
reader.readAsDataURL(file);
},
function(e) {
alert(e.message);
});
});
});
小闹 (作者)
我这边没有问题,你检查一下代码吧
-
你好,我用上面代码写的不执行,能给指导下吗?
<script>
var addr1 = document.getElementById("paoteooo1").src;
var addr2 = document.getElementById("paoteooo2").src;
function plusReady(){
plus.io.requestFileSystem(plus.io.PRIVATE_WWW,
function(fs) {
var rootEntry = fs.root;
var reader = null;
rootEntry.getFile(addr1, {},
function(entry) {
entry.file(function(file) {
reader = new plus.io.FileReader();
reader.onloadend = function(e) {
plus.console.log("Read success");
// Get data
plus.console.log(e.target.result);
};
reader.readAsDataURL(file);
},
function(e) {
alert(e.message);
});
});
});
}
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready",plusReady,false);
}
</script>
2015-10-19 15:10
data:audio/amr;base64,IyFBTVIKPJEXFr5meeHgAeev8AAAAIAAAAAAAAAAAAAAAAAAAAA8SHcklmZ54eAB57rwAAAAwAAAAAAAAAAAAAAAAAAAADxVAIi2Znnh4AHnz/AAAACAAAAAAAAAAAAAAAAAAAAAPEj5H5ZmeeHgAeeK8AAAAMAAAAAAAAAAAAAAAAAAAAA8VP0ftmZ54eAB58/wAAAAgAAAAAAAAAAAAAAAAAAAADxI9R+WZnnh4AHnivAAAADAAAAAAAAAAAAAAAAAAAAAPFT9H7ZmeeHgAefP8AAAAIAAAAAAAAAAAAAAAAAAAAA8SPUflmZ54eAB54rwAAAAwAAAAAAAAAAA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ADjRapuS8oLqaLI/tsM5e7BBXtn7oidAPARuXo4R2QtBJNnIRqdKgx6lRm7yGoAOkTrgM0jUk4A8GrpjOOe6TcAfw1p2Gbhk5ob62w0cdK001vNe1GoxQDwO7I3//noQgQ6l33AEWPiCUf8GCRSApbnmg5bwWY/wPDS7KZBTmgBBwUp6QRwdiMFTpV86BPi6NiFlWkYIyVA8BJFmzpQUB2EOAupOLhiw+Y2uTsQ09EHwZXLb9h6AQDwePotPuuwBASSqP/YLcLWU/JRH96Tilxj3ehwvtM+APAi5X8NuOIHgW2WKKF0TSecB6FMCb6FvPMPDDZQfqwA8Tutz7W0UZyeB4FpRJkSf1uR1/aZKkkwS3/D1RlyyQDzgxnSzHswBgeMpSjTye6vowORbeRuLdlvDoVP4cuBgPBpxc0//UAHBeWmq1lIKdP5Q1hNMYldwB5q/GXXx2KA8BKkkievKAaHC+LolMh 这是我转换完的音频 播放不了,你们可以播放吗
趴趴熊
如果我想得到base64编码,应该是var v = reader.readAsDataURL(file)还是var v = e.target.result;还是其他的?
2015-10-20 11:34
stock2
var v = e.target.result
2015-10-20 13:15
趴趴熊
回复 stock2:谢谢
2015-10-20 15:36
stock2
不客气 :D
2015-10-20 18:05
奎子
为什么
reader.onloadend = function(e) {
plus.console.log("Read success");
// Get data
plus.console.log(e.target.result);
};
没法进入 这个方法里面??
2016-03-07 15:13
w***@163.com
为什么我用安卓的可以,用苹果的测试就取不到base64?
plus.io.requestFileSystem()这个都执行不了,是路径问题吗
2016-07-07 17:23
freedemon
回复 w***@163.com:对啊对啊 情况跟你一样,哥们你解决了吗
2016-08-09 16:43
freedemon
安卓没问题,为什么ios发的WAV却不行,查看了一下rootEntry.getFile方法进不了。
2016-08-09 16:45