cordova-plugin-nativeaudio
cordova-plugin-nativeaudio copied to clipboard
Plugin stops background music
When I playback a Sound-File with this plugin in Android, it stops music in the background (Napster-App in my case) and doesn't resume the music afterwards. Here is my code:
window.plugins.NativeAudio.preloadSimple( file, 'sound/'+file, function(msg){ console.log("sound loaded:"+file); window.plugins.NativeAudio.play( file ); window.setTimeout( function(){ console.log("Sound unloaded"); window.plugins.NativeAudio.unload( file ); }, 1000 * 5 );
Is there a way to fix that?
There's already an issue (#105) about this. Would be nice to keep the conversation in one place.
Thanks to @ThibaudD for the pull request #117 to fix this issue.
@floatinghotpot On Android, 6.0.1, it still pauses music.
Original code (uses ionic):
NativeAudio.preloadSimple("ding", "assets/sounds/ding.mp3");
Updated to latest version, of course.
Still getting this issue with simple and complex sounds on iOS.
Also still getting this issue on Android, when loading a simple sound. Has anyone found a fix or a workaround?
Please check if pull request #139 fixes it for you
@Rodmg No it doesn't. The nativeaudio plugin stops Apple Music when the app loads. When a sound is played in the app, the plugin stops any music app playing — and takes over the iOS audio player in control center.
Looking forward to a permanent fix for this issue.
Hi everyone. I solved this problem. ı edited plugin files and it is working...
You should find this file in your project.
yourworkspace/platforms/android/src/com/rjfun/cordova/plugin/NativeAudioAssetComplex.java
and you make comment this line
..... private void invokePlay( Boolean loop ) { Boolean playing = mp.isPlaying(); if ( playing ) { //mp.pause(); THIS LINE mp.setLooping(loop); mp.seekTo(0); mp.start(); } if ( !playing && state == PREPARED ) { state = (loop ? PENDING_LOOP : PENDING_PLAY); onPrepared( mp ); } else if ( !playing ) { state = (loop ? PENDING_LOOP : PENDING_PLAY); mp.setLooping(loop); mp.start(); } }
Now your app playing on background...
That's all... :)
don't working for ionic 4.x with android 8.1 sdk. if screen go to standby audio is pause.
Same thing on android 10, music is paused, even with this https://github.com/floatinghotpot/cordova-plugin-nativeaudio/pull/139/files
Same problem as @julianCast here
Same problem here on iOS 13. It stops the background music and also, the case where an iFrame video with music is playing.
Edit:
I noticed Capacitor now has simple and complex preloads. I'm not familiar with Java or writing Cordova plugins though I know some Swift. Would this be a doable migration to Cordova?
https://github.com/capacitor-community/native-audio
cc @ThibaudD @floatinghotpot