简体   繁体   中英

Hybrid Cordova app : no sound in local on Android

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM