Author Topic: BASS for Android  (Read 833415 times)

Ian @ un4seen

  • Administrator
  • Posts: 26140
BASS for Android
« on: 21 Nov '11 - 16:23 »


Android versions of BASS and the add-ons can be found on the BASS webpage.






The libraries include support for Java code (via BASS classes), as well as native code (via the usual BASS headers). The Java API follows the C/C++ API as much as possible, but there are some unavoidable differences, mainly in parameter/return types. The BASS classes are included in source form (eg. BASS.JAVA file), so you can see exactly what's what in there. Java versions of the DSPTEST/FXTEST/LIVESPEC/NETRADIO/PLUGINS/RECTEST/SPECTRUM and MIDITEST examples are included (along with Android Studio projects) to demonstrate things. Note the add-on JAVA files (containing an add-on's class) are only needed when calling the add-on's functions (as in MIDITEST), not when using the plugin system (as in PLUGINS).

BASS can use any of Android's AAudio, OpenSL ES, and AudioTrack APIs for output. By default, AAudio is used on Android 8.1 and above, and OpenSL ES on older Android versions. AudioTrack output is also available via the BASS_DEVICE_AUDIOTRACK flag. AAudio can be disabled (in favour of OpenSL ES) by setting the BASS_CONFIG_ANDROID_AAUDIO config option to 0. AAudio can also be enabled on Android 8.0 by setting that to 1 but some devices have a problem with it. The BASS_CONFIG_DEV_BUFFER config option determines the device/output buffer size used by BASS. That currently defaults to 40ms. When AudioTrack output is used, the buffer size will always be at least the length given by the AudioTrack.getMinBufferSize function. BASS_Init will default to using the device's native sample rate (as reported by AudioTrack.getNativeOutputSampleRate) rather than the rate provided in the "freq" parameter, but that can be overridden via the BASS_DEVICE_FREQ flag. High resolution output is supported on Android 5, while older Android versions are limited to 16-bit output. 16-bit output can be forced via the BASS_DEVICE_16BITS flag.

With Android 5 or above, BASS can make use of Android's built-in codecs. Different devices will have different codecs available, but AAC and FLAC will generally be supported by all. Other formats that may be supported include ALAC/APE/MIDI/OPUS. BASS will still read APE/ID3/ID3V2/MP4 tags and make them available via the usual tag options, but other tag types (eg. OGG) won't be available when using the OS's codecs. The MediaMetadataExtractor class could be used to get tags in that case. When an Android codec is used by a stream, its "ctype" will be set to BASS_CTYPE_STREAM_AM. The BASS_TAG_AM_MIME tag gives the MIME type of the file, and the BASS_TAG_AM_NAME tag gives the name of the decoder that's being used. It appears that some decoders set the MIME type to "audio/raw" rather than the actual file format. The file extension could be used to infer the file format in that case, or the MediaMetadataExtractor class could be used. BASS will handle the reading of AAC/ADTS data, but other file formats will be handled by Android and so will not be supported with custom file routines, ie. BASS_StreamCreateFileUser. As on other platforms, any BASS add-ons that are loaded via BASS_PluginLoad will have priority over the OS's codecs. The use of Android's codecs can be disabled via the BASS_CONFIG_AM_DISABLE config option.

For convenience, the stream/sample/music creation functions include support for assets, via an "Asset" class. For example, a stream could be created from a "music.ogg" asset like this...

Code: [Select]
stream = BASS.BASS_StreamCreateFile(new BASS.Asset(getAssets(), "music.ogg"), 0, 0, 0);

The stream/sample/music creation functions also include support for the ParcelFileDescriptor class, which can be used to access scoped storage. BASS will close the file descriptor when it is time to do so (eg. when a stream is freed), so you do not need to do that.

BASS will attempt to use the system's SSL libraries (OpenSSL or BoringSSL) to support HTTPS URLs, but that is not possible for apps that target Android 7 (API level 24) or above. Apps that target a lower Android version will still work on Android 7. A BASS_SSL add-on (based on OpenSSL) is available to add HTTPS support for apps that do target Android 7 or above. It can also be used with lower Android versions if wanted (it has priority over the system's SSL libraries). No additional code is required to enable it; simply put the BASS_SSL library alongside the BASS library.

When using ProGuard to obfuscate your Java code, the BASS classes should be left alone, like this:

Code: [Select]
-keep class com.un4seen.bass.** {*;}
« Last Edit: 17 Nov '21 - 16:44 by Ian @ un4seen »

fstarred

  • Posts: 106
Re: BASS for Android
« Reply #1 on: 21 Nov '11 - 20:14 »
Congratulations !!!

BASS library rocks !!!  8)

Ionut Cristea

  • Posts: 1559
Re: BASS for Android
« Reply #2 on: 21 Nov '11 - 23:45 »
  I've tried to make an application with Eclipse. I've build with both ARMv5 and ARMv7. Every bass call i make make application to crash.

Ian @ un4seen

  • Administrator
  • Posts: 26140
Re: BASS for Android
« Reply #3 on: 22 Nov '11 - 14:04 »
What does Eclipse say about the crash, eg. is there an exception and/or is there anything in the log? If it's happening with every BASS call, perhaps the problem is that the BASS library can't be found. Did you copy the LIBS folder into your project's folder? After doing that, you may also need to refresh the Eclipse project (the LIBS folder should be shown in the project's contents).

If you're still having any trouble with it, please check whether the same thing happens when you try to run the examples.

Ionut Cristea

  • Posts: 1559
Re: BASS for Android
« Reply #4 on: 22 Nov '11 - 14:11 »
"The application .... has stopped unexpectedly. PLease try again"


this happens with my application, and bass samples also. I've included libbass

Ian @ un4seen

  • Administrator
  • Posts: 26140
Re: BASS for Android
« Reply #5 on: 22 Nov '11 - 15:02 »
That looks like a message displayed on the device rather than in Eclipse? Please also check what Eclipse has to say about it in its debug perspective, eg. there should be some details in the "LogCat" view.

To confirm that the problem is happening on the first BASS call, have you placed a breakpoint on the call and then tried stepping over (F6) it? If it reaches the breakpoint and then crashes when you step over the call, does it make any difference what the call is, eg. does it happen even with a BASS_GetVersion call? Note the app should be started in "Debug" mode (rather than "Run") when doing this.

Ionut Cristea

  • Posts: 1559
Re: BASS for Android
« Reply #6 on: 22 Nov '11 - 15:20 »
Thread [<1> main] (Suspended (exception UnsatisfiedLinkError))   
   Runtime.loadLibrary(String, ClassLoader) line: 429   
   System.loadLibrary(String) line: 554   
   BASS.<clinit>() line: 612   
   NetRadio.onCreate(Bundle) line: 183   
   Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1047   
   ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1611   
   ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1663   
   ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 117   
   ActivityThread$H.handleMessage(Message) line: 931   
   ActivityThread$H(Handler).dispatchMessage(Message) line: 99   
   Looper.loop() line: 123   
   ActivityThread.main(String[]) line: 3683   
   Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]   
   Method.invoke(Object, Object...) line: 507   
   ZygoteInit$MethodAndArgsCaller.run() line: 839   
   ZygoteInit.main(String[]) line: 597   
   NativeStart.main(String[]) line: not available [native method]   

Ian @ un4seen

  • Administrator
  • Posts: 26140
Re: BASS for Android
« Reply #7 on: 22 Nov '11 - 15:45 »
Thread [<1> main] (Suspended (exception UnsatisfiedLinkError))   
   Runtime.loadLibrary(String, ClassLoader) line: 429   
   System.loadLibrary(String) line: 554   
   BASS.<clinit>() line: 612   

That does look very much like the BASS library can't be found :)

Is the LIBS folder shown in Eclipse, and if you open it, do you see the ARMEABI(-V7A) subfolders and LIBBASS.SO files in there? If not, try refreshing the project (right-click and choose "Refresh").

Ionut Cristea

  • Posts: 1559
Re: BASS for Android
« Reply #8 on: 22 Nov '11 - 22:56 »
Quote
Is the LIBS folder shown in Eclipse, and if you open it, do you see the ARMEABI(-V7A) subfolders and LIBBASS.SO files in there? If not, try refreshing the project (right-click and choose "Refresh").

Yes is there :(

Ian @ un4seen

  • Administrator
  • Posts: 26140
Re: BASS for Android
« Reply #9 on: 23 Nov '11 - 14:14 »
Does your "Package Explorer" view in Eclipse look like the attached image? To confirm whether the BASS library is being included in the app's package, you can go to the project's BIN directory and open the APK file with a ZIP archiver; you should find a LIB folder in there (with the same contents as the project's LIBS folder).

Ionut Cristea

  • Posts: 1559
Re: BASS for Android
« Reply #10 on: 23 Nov '11 - 15:06 »
Yes the tree folder is similar and i can find libbass.so in the .apk file :)
Here is my compiled netradio example

Ian @ un4seen

  • Administrator
  • Posts: 26140
Re: BASS for Android
« Reply #11 on: 23 Nov '11 - 16:07 »
The LIBBASS.SO file is in the root of your package instead of in a LIB folder, so that explains why it isn't being found. When you say your project looks similar, how similar is that? :) ... The LIBS branch should look identical. If it is identical and still not working, please upload the entire project folder to have a look at, to hopefully find out what is going wrong with it.

Ian @ un4seen

  • Administrator
  • Posts: 26140
Re: BASS for Android
« Reply #12 on: 24 Nov '11 - 16:47 »
There were problems with the MO3 and IT file loaders, so an updated library is up (in the 1st post) to fix that. An FXTEST example has also been added.

bjadams

  • Posts: 9
Re: BASS for Android
« Reply #13 on: 28 Nov '11 - 20:45 »
Does it support the Android NDK or is it Java only, as I could not find and NDK examples in the zip archive?
« Last Edit: 28 Nov '11 - 21:57 by bjadams »

Ian @ un4seen

  • Administrator
  • Posts: 26140
Re: BASS for Android
« Reply #14 on: 29 Nov '11 - 15:25 »
Yes, it should be possible to use the BASS library in native code too, with the standard BASS.H header. The header isn't included in the package above, but it can be taken from one of the other BASS platform packages (it's the same header for all platforms).

Meanwhile... Android versions of the BASSFLAC and BASSWV add-ons have been added to the package, as well as a PLUGINS example. The BASS library has also had a little update to add support for that stuff.

bjadams

  • Posts: 9
Re: BASS for Android
« Reply #15 on: 29 Nov '11 - 23:11 »
I still can't find 1 example or some step-by-step guide how to add all the necessary BASS bits to my current Android project so that I can use it natively.
Is there any chance to put in at least 1 simple example or some quick guide?

materialworlds

  • Posts: 17
Re: BASS for Android
« Reply #16 on: 30 Nov '11 - 10:41 »
Any timescale for an Android version of BASS FX ? :)
« Last Edit: 30 Nov '11 - 10:58 by materialworlds »

Ian @ un4seen

  • Administrator
  • Posts: 26140
Re: BASS for Android
« Reply #17 on: 30 Nov '11 - 17:09 »
I still can't find 1 example or some step-by-step guide how to add all the necessary BASS bits to my current Android project so that I can use it natively.
Is there any chance to put in at least 1 simple example or some quick guide?

I'm afraid there aren't currently any examples for using BASS in native Android projects. Are you looking for help on using BASS (function calls/etc) or on how to include the library in a native Android project? The BASS calls will be the same as on other platforms, so you could have a look at the examples from the other platform BASS packages (be sure to also check the documentation for usage details). Regarding including the library in a native project, I think you would do something like this in your "Android.mk" file...

Code: [Select]
include $(CLEAR_VARS)
LOCAL_MODULE := bass
LOCAL_SRC_FILES := path/to/bass/libs/$(TARGET_ARCH_ABI)/libbass.so
LOCAL_EXPORT_C_INCLUDES := path/to/bass
include $(PREBUILT_SHARED_LIBRARY)

And then add this to your app's build rules...

Code: [Select]
LOCAL_SHARED_LIBRARIES := bass

bjadams

  • Posts: 9
Re: BASS for Android
« Reply #18 on: 30 Nov '11 - 21:11 »
I was mainly just looking for the steps necessary to setup the bass in my android project, not the actual BASS calls which would be the same for Windows (which I already had used once in the past).

Will test the suggested setup and report back!

Thanks for the great support!

bjadams

  • Posts: 9
Re: BASS for Android
« Reply #19 on: 1 Dec '11 - 07:09 »
As soon as I include the BASS lib details in Android.mk, and put all the relevant library files in place, I am getting a process closed error as soon as my app launches. I am not even doing any BASS api calls in my app yet!

I unzipped the apk and LIBbass is being included in the package.

Ian @ un4seen

  • Administrator
  • Posts: 26140
Re: BASS for Android
« Reply #20 on: 1 Dec '11 - 16:02 »
That's strange. Does the problem go away if you simply remove BASS from the project and leave everything else untouched? Do you see any information on what happened in the "LogCat" view? If the problem persists, please upload the APK file to have a look at here...

   ftp.un4seen.com/incoming/

bjadams

  • Posts: 9
Re: BASS for Android
« Reply #21 on: 2 Dec '11 - 06:53 »
The vanilla project, without bass included works perfectly. As soon as I put the bass information in android.mk, the app crashes at launch.

I am using the AGK Opengl api. Can I email you the project in private, or is the ftp private?

Thanks a lot for support.

ken

  • Posts: 752
Re: BASS for Android
« Reply #22 on: 2 Dec '11 - 08:39 »
Hi,

Anyone tried BASS for Android with Titanium? I know Titanium can use 3:rd party "plugins"

http://www.appcelerator.com/products/titanium-mobile-application-development/


bjadams

  • Posts: 9
Re: BASS for Android
« Reply #23 on: 2 Dec '11 - 13:32 »
Uploaded a zip on the ftp with 2 projects. 1 without Bass, and one with the bass libs added to android.mk (this one crashes on app launch)

Ian @ un4seen

  • Administrator
  • Posts: 26140
Re: BASS for Android
« Reply #24 on: 2 Dec '11 - 16:44 »
Uploaded a zip on the ftp with 2 projects. 1 without Bass, and one with the bass libs added to android.mk (this one crashes on app launch)

Java will look in the app's "lib" folder for shared libraries, but I don't think the OS does that, ie. the app's "lib" folder isn't in the library search path, so the LIBBASS.SO file can't be found and the app can't be launched. One way around it that seems to be working is to change the "SONAME" entry in the LIBBASS.SO file to the full installation path (eg. "/data/data/<packagename>/lib/libbass.so"), but that isn't very elegant. I'll see if I can find a better way around it.