NativeAudioService use with several audio files

82 views Asked by At

About Android, I use the NativeAudioService, now. That works fine with my smartphone. I have tested it with a single audio file, as mentioned in the example defined in javafxports how to call android native Media Player.

Question 1 (Solved)

Now, if I want to listen several sounds (several files) with this service, how can I do? The example includes an explicit and single audio filename ("audio.mp3") in the AndroidNativeAudio class and the service does not accept any parameter as an audio filename:

service = (NativeAudioService)
Class.forName("com.gluonhq.nativeaudio.AndroidNativeAudio").newInstance();

Question2 (Solved)

There are four methods about native audio service (play, stop, pause, resume). They work fine. But MediaPlayer class also provides other methods like setCycleCount, setVolume and setAutoPlay. Are there some extensions of this AndroidNativeAudio class that provide them too?


My solution for solving these two questions is:

  • In AndroidNativeAudio class, create the attributes (ex.: nbCyclesCount, audioLevel) .Then, modify its play method for taking into account the nbCyclesCount. And create a setAudioLevel method.

  • At the end, when the service (instance of AndroidNativeAudio ) is prepared, assign these attributes before playing it.

Question3 (To solve)

It remains a BIG problem of the play method (in AndroidNativeAudio class), it is not possible to hear two sounds at the same time (simultaneously) by:

  • creating an instance 1 for a sound1

  • creating an instance 2 for a sound2

Sound1 is heard until Sound2 is created. After, only Sound2 is heard.

Is it due to the number of codec instances of my phone, as mentioned in https://developer.android.com/reference/android/media/MediaPlayer.html#release() ?

How to simultaneously hear several sounds in an android? The SoundPool class seems to be a solution? Already used in Smartphones games?

See the answer in: AudioTrack, SoundPool or MediaPlayer Which Should I use?

THE SOLUTION: I use the AndroidNativeAudio class and NativeAudioService interface. I have tested it on Android: it works fine with at least 5 simultaneous sounds on my phone.

0

There are 0 answers