Jav*_*rif 1 phonegap-plugins angularjs cordova ionic-framework
我使用离子与cordova-plugin-media录制音频,我想使用angular-file-upload上传录制到服务器的音频,但我不知道如何从Media获取文件.我试试这个:
控制器:
$scope.itemOnLongPress = function (id) {;
myMedia = new Media("./sound/recorded.wav");
myMedia.startRecord();
}
$scope.itemOnTouchEnd = function (id) {
myMedia.stopRecord();
myMedia.play();
window.resolveLocalFileSystemURI(myMedia.src,
// success callback; generates the FileEntry object needed to convert to Base64 string
function (fileEntry) {
// convert to Base64 string
function win(file) {
var reader = new FileReader();
reader.onloadend = function (evt) {
var obj = evt.target.result; // this is your Base64 string
alert(obj);
};
reader.readAsDataURL(file);
};
var fail = function (evt) {};
fileEntry.file(win, fail);
},
// error callback
function () {
alert('fail');
}
);
Run Code Online (Sandbox Code Playgroud)
我从事件中"失败"的所有时间,我尝试使用一些前缀,如:"/ sdcard/recorded.wav","file:///sound/recorded.wav","documents://recorded.wav"但每次同样的错误......
有谁知道我怎么能得到这个文件?
最后我使用cordova插件(cordova-file-transfer)来做它并获取我使用的文件:
window.requestFileSystem(LocalFileSystem.TEMPORARY,0,function(filesystem) {
var file = filesystem.root.toUrl;
/*and need remove file:// from path so..*/
file = file.slice(7)
}
Run Code Online (Sandbox Code Playgroud)
我希望这对某人有所帮助,我浪费了很多时间.
| 归档时间: |
|
| 查看次数: |
1140 次 |
| 最近记录: |