B4A Library [Lib] OpenSL sound player

Hello,

When I realized there were a few issues with SoundPool (crashes are reported with the Samsung Galaxy S2 for example), I tried to find an alternative. There are two: OpenSL and OpenAL, but only OpenSL is interesting because it is already delivered with your OS since Gingerbread and it is hardware-accelerated. Unfortunately OpenSL ES is not a Java library and there's nothing in the API to call its methods. So I had to write the .so libraries in C, then the wrapper in Java.

The big advantage over SoundPool (except it doesn't crash on some devices) is that you're not limited by the sound duration or the file size. You can use it to play music if you wish. The big drawback is that you cannot play any sound format. Only PCM 16 bits, 44.1 khz. I don't have enough time to write a decoder for the MP3 and OGG formats.
Another advantage is that you can extend the possibilities (recording, 3D audio effects...) by calling other methods (if you add their declaration in the C code).

The library is provided as-is, with all the source code (C & Java). The C code is a modified version of the following project:
https://code.google.com/p/opensl-soundpool/
and needs the NDK to be compiled.

Since I don't want to maintain this project, I won't answer to questions and won't update the library.
 

Attachments

  • OpenSLPlayer.zip
    379 KB · Views: 1,025

Shay

Well-Known Member
Licensed User
Longtime User
Hi

First great one

I am trying to play the 3 files one after the other
but it plays them at the same time
I tried also to reduce the channels to 1 (instead of 8 in the example)
how can I do it without sleep?
 

Informatix

Expert
Licensed User
Longtime User
This library, as all audio libraries, play sounds in the background. Therefore the Play statement does not wait the end of the sound playback. If you put three Play in sequence, the three sounds will be played almost together.
If you want to play one sound after another (but are we talking of sounds? because this behavior is expected for music, not sounds), we have to listen to the End event of each sound. Unfortunately, I did not implement this event in the OpenSL library and this event is also missing in the Soundpool library (for the same reason: it is not very useful for sounds). So your only solution left is the MediaPlayer library.
 

sterlingy

Active Member
Licensed User
Longtime User
Informatix, I've implemented this lib, and it has solved my problem that was encountered and discussed in the libGDX thread. I know you are not offering support for this lib, but thought I would mention that upon completion of playback of my audio, I hear something that is reminiscent of a camera shutter on a dSLR.

This is not evident if I play the sound with a media player on the PC, and I edited the file to cut the end off to make sure there wasn't some bogus noise.

I also commented out all other sounds to make sure it wasn't referencing something else.

Best,

SterlingY
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…