floatinghotpot/cordova-plugin-nativeaudio

Can this plugin be used for notification sound playing effectively?

Opened this issue · 0 comments

  • Is there a configuration to avoid requesting focus gain indefinitely when loading audio assets
  • Is there a Fork out there that supports notification type of sounds better?

Basically I'm trying to not get sound focus when preloading assets and lower other sounds only when Im playing a notification (something like AUDIOFOCUS_LOSS_TRANSIENT in android)

In android I managed to achieve this by moving this from pluginInitialize to play and , changing the options to STREAM_NOTIFICATION and AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:

		AudioManager am = (AudioManager)cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);

	        int result = am.requestAudioFocus(this,
	                // Use the music stream.
	                AudioManager.STREAM_MUSIC,
	                // Request permanent focus.
	                AudioManager.AUDIOFOCUS_GAIN);

And adding a release focus on the stop

AudioManager am = (AudioManager)cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
      am.abandonAudioFocus(this);

but I fear that Im stretching the boundaries of this plugin and trying to make it do something it's just not meant to do.