Skip to content Skip to sidebar Skip to footer

Ionic/cordova App Plays Sound In Emulator But Not On Android Device

I'm new to Ionic and Cordova, so I'm sure I'm missing something basic, but my problem is a packaged APK does not play sounds on an Android device. I can get the sound to play in t

Solution 1:

Turns out that you have specify path starting with the /android_asset/www prefix like so:

/android_asset/www/

So changing my code to the following worked. Note you'll want to detect what device you're running on to determine the appropriate location.

.controller('MainCtrl', ['$scope', function ($scope) {
        ///android_asset/www/
        $scope.playStartBell = function () {
            var media = newMedia('/android_asset/www/media/startBell.mp3', function () {
                console.log('good');
            }, function (err) {
                console.log('bad: ', err);
            });
            media.play();
        },
            $scope.playStopBell = function () {
            var media = newMedia('/android_asset/www/media/stopBell.mp3', function () {
                console.log('good');
            }, function (err) {
                console.log('bad: ', err);
            });
            media.play();
        }
    }])

Post a Comment for "Ionic/cordova App Plays Sound In Emulator But Not On Android Device"