I use org.apache.cordova.file and org.apache.cordova.file-transfer and ngcordova.js to create dir.
$cordovaFile.createDir('test/').then( function(dirEntry) {
alert('createDir1');
}, function(err){
alert('createDir1' + JSON.stringify(err));
});
// Create dir aganin in dir test
$cordovaFile.createDir('test/one/').then( function(dirEntry) {
alert('createDir2');
}, function(err){
alert('createDir2' + JSON.stringify(err));
});
And download a audio file to the dir.
$scope.downloadFile = function(){
var url = "http://7u2lg5.com1.z0.glb.clouddn.com/top10/Sample.mp3";
var targetPath = cordova.file.documentsDirectory + "test/one/" + "Sample.mp3";
var trustHosts = true
var options = {};
$cordovaFileTransfer.download(url, targetPath, options, trustHosts).then(function(result) {
alert("success .....")
}, function(err) {
alert("error .....")
}, function (progress) {
$timeout(function () {
$scope.downloadProgress = (progress.loaded / progress.total) * 100;
})
});
}
So now I want to use org.apache.cordova.media to play it.
$scope.playfile = function(){
var src = cordova.file.documentsDirectory + "test/one/Sample.mp3";
MediaSrv.loadMedia(src).then(function(media){
media.play();
});
}
Please see How to play local audio files
This method can play a remote audio.But now it’s can’t paly a local audio.
So I need help.
Please help me !!