Cordova Media will not play mp3 from www

I found many possible solutions to this problem in StackOverflow, but it does not seem to solve it for me. I am trying to play an mp3 file in my Cordova application (3.5) usingorg.apache.cordova.media@0.2.10

var sound = new Media('audio/el/hello.mp3');
sound.play()

But it just won’t play, and I get the following error in LogCat

MediaPlayer error (1, -2147483648)

I tried serving the folder locally and the following steps point to the same file

var sound = new Media('http://10.0.2.2:9999/www/audio/el/hello.mp3');
sound.play()

This suggests that this is not because the file has an encoding problem.

I was unable to use the latest version of the plugin mediabecause the event devicereadynever fires.

Update . I just tried unzipping the files to persistent storage and playing them there, and I get the same error.

. AudioPlayer.java, , www , FileNotFoundException f == "www/el/hello.mp3"

fd = this.handler.cordova.getActivity().getAssets().openFd(f);

, assets, .

+4
3

. :

var getPathMedia = function () {
var path = window.location.pathname;
var phoneGapPath = path.substring(0, path.lastIndexOf('/') + 1);
// Return path at www folder
return 'file://' + phoneGapPath;
};
var media = new Media(getPathMedia() + 'media/message.mp3');
media.play();
+6

www.

Android:

var media = new Media("/android_asset/www/audio/el/hello.mp3",
    successFunction,
    errorFunction
);

iOS, /android_asset/www/, iOS .

IOS:

var media = new Media("audio/el/hello.mp3",
    successFunction,
    errorFunction
);
+3

, , , , .

What I needed to do was not get the location, but the current URL of the page I was on. From this, I could create the URL of the asset that I wanted to play.

var path = window.location.href;
var phoneGapPath = path.substring(0, path.lastIndexOf('/') + 1);
var media = new Media(phoneGapPath + 'media/message.mp3');
media.play();

hope this helps

0
source

Source: https://habr.com/ru/post/1547555/


All Articles