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

2 Likes

What do the error logs say?

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

@nicraboy, @loicknuchel
when I check the dir.
image

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

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