0

I am working on a hybrid android app using Cordova for the Galaxy Tab E. Everything works as expected on my computer browser, same thing on my tab except for my audio files, but the sound is not working.

What I tried : - Use HTML5 with on a button, image... : no sound (on the tab) - Use JavaScript with « onclick » on a button, image... same - Cordova Media Plugin with the associated script : same - Try to change the path /www/audio/ with /android_assets/www/audio/ or file:/// (...) : same thing everywhere - Try to change a .wav or .mp3 : same

It only works both on computer and on the tab when I use an URL to link the MP3, but not in local (and that’s definitely what I must implement, cause tabs will not have an internet connection)

Kindly guide to solve this issue, thanks.

Usman Khan
  • 3,739
  • 6
  • 41
  • 89

1 Answers1

0

Its probably best to follow the second answer given here How to get Path for local mp3 file from www in Phonegap IOS?

to generate the file path, however with that caveat this is the code that worked for me on Android with cordova-plugin-media:

audioSuccess = loadAudio('sounds/success.wav');

function loadAudio(file) {

        var path = window.location.pathname;
        path = path.substr(path, path.length - 10);
        var id = path + file;
        console.log('loading audio: ' + id);
        var my_media = new Media(id,
            // success callback
            function () { console.log("loadAudio():Audio Success on id - now setting volume " + id);},
            // error callback
            function (err) { console.log("loadAudio():Audio Error: " + JSON.stringify(err) + ' on id ' + id); }
            );
        return my_media;
    };

audioSuccess.play();
MStoner
  • 730
  • 4
  • 10
  • Actually its probably better to follow the second answer given here as paths have different lengths on different environments: https://stackoverflow.com/questions/28339389/how-to-get-path-for-local-mp3-file-from-www-in-phonegap-ios – MStoner Nov 01 '19 at 08:26