I am trying to use this plugin with my PhoneGap Build app: https://www.npmjs.com/package/cordova-plugin-nativeaudio
I call it in my config.xml
<gap:plugin name="cordova-plugin-nativeaudio" source="npm" />
Then in my onDeviceReady I load the sound like so:
if( window.plugins && window.plugins.NativeAudio ) {
window.plugins.NativeAudio.preloadSimple( 'slide', 'sounds/slide.mp3', function(msg){
}, function(msg){
alert( 'error: ' + msg );
});
}
else {
alert("load failed");
}
and then in my function that happens every time a move a is made I put
window.plugins.NativeAudio.play( 'slide' );
Then I package and build the app and install on my phone via TestFlight
The sound is stored in my www/sounds/
folder, if I change the path/filename in the loading code my phone will alert "load failed", but with the correct path it remains silent implying a success. And yet it plays no sounds when called.
I have tried to play the same sound via the Media plugin and it worked so I know there is nothing wrong with the .mp3 itself, but it was being called to many times for Media to handle freezing up the app.
EDIT: Will accept suitable alternatives if this plugin is broken or outdated.
I have tested the plugin and it works just fine.
You can try their sample project
At first I tried with your code and a sound I downloaded from internet and I was getting this error when trying to play it:
WARNING: [0x1f197000] 998: Failure to setup sound, err = -50
(Got success callback on the preload, and this was displayed on the Xcode debug area when calling play)
And the problem was that the sound was to complex to be played with preloadSimple
, using preloadComplex
fixed the issue for me, so maybe your sounds are too complex to be played with preloadSimple
Note: when using preloadComplex
you have to pass three params before the success callback, volume, voices, delay, should be something like:
window.plugins.NativeAudio.preloadComplex( 'slide', 'sounds/slide.mp3', 1, 1, 0,
function(msg){
window.plugins.NativeAudio.play( 'slide' );
}, function(msg){
alert( 'error: ' + msg );
});