|
发表于 2020-2-26 19:15:27
|
显示全部楼层
// 根据系统时间产生文件名
this.fileName = justep.Date.toString(new Date(), "yyyyMMddhhmmss") + ".wav";
var path;
if (device.platform == "iOS") {
path = cordova.file.tempDirectory + this.fileName;
} else if (device.platform == "Android") {
path = cordova.file.externalRootDirectory + this.fileName;
}
this.mediaRec = new Media(this.fileName, function() {
me.comp('audio_name').set({
value : me.fileName
});
// device.platform
window.resolveLocalFileSystemURL(path, onResolveSuccess, errorHandler);
function onResolveSuccess(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
var callback = evt.target.result;
me.Audio_Base64= callback.split(',')[1]; //此处得到语音文件 base64格式,可以用作上传
};
reader.readAsDataURL(file);
}, errorHandler);
}
function errorHandler(e) {
console.log('读取文件失败');
}
console.log(path);
isOk = '1';
}, function(err) {
isOk = '0';
me.comp('audio_name').set({
value : "录音失败,请尝试重启手机后重试"
});
me.comp("btn_播放录音").set({
disabled : false
});
}); |
|