Problem of download audio file and play this audio

I use org.apache.cordova.file and org.apache.cordova.file-transfer and ngcordova.js to create dir.

$cordovaFile.createDir('test/').then( function(dirEntry) {
    }, function(err){
      alert('createDir1' + JSON.stringify(err));

    // Create dir aganin in dir test
    $cordovaFile.createDir('test/one/').then( function(dirEntry) {
    }, function(err){
      alert('createDir2' + JSON.stringify(err));

And download a audio file to the dir.

$scope.downloadFile = function(){
    var url = "";
    var targetPath = cordova.file.documentsDirectory + "test/one/" + "Sample.mp3";
    var trustHosts = true
    var options = {};

    $, targetPath, options, trustHosts).then(function(result) {
      alert("success .....")
    }, function(err) {
      alert("error .....")
    }, function (progress) {
      $timeout(function () {
        $scope.downloadProgress = (progress.loaded / * 100;

So now I want to use to play it.

$scope.playfile = function(){
    var src = cordova.file.documentsDirectory + "test/one/Sample.mp3";

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 !!


What do the error logs say?

@nicraboy, @loicknuchel
I run this app on a ios device.
In the safari console, I get a error.

@nicraboy, @loicknuchel
when I check the dir.

when I play the audio file.I get the file path.

And then the safari popup the error…, I don’t know why…

Hi there,

I was also having similar problem on ios. Here is my post.

Finally after lot of struggle I mananged to get it working with the solution posted here. Chris who has raised the issue , he himself posted a solution, that is the one which worked for me.

Apparently this problem is faced by those who are on cordova 3.3+ , media plugin is not really compatible with the way file paths are returned by file plugin.

Has there been any solutions to this?

1 Like

could be guilty of the type of file ?
There are problems on ios with mp3?
it is better to use the wav file or another type?

do you guys have a working solution? I have been trying to resolve this for a week now.

Has any come up with a solution already? Thanks