Author Topic: [Solved] BASS_Init giving BASS_ERROR_UNKNOWN on Android  (Read 288 times)

lfeng

  • Posts: 5
Hi,
I got BASS_Init failure with BASS_ERROR_UNKNOWN on Android (using BASS.NET library), see below code:
Code: [Select]
if (!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_AUDIOTRACK, default(IntPtr)))
{
    Trace.TraceError($"Bass.Init fail! errcode:{Bass.BASS_ErrorGetCode()}");
    return;
}

Version info:
Bass version: 2.4.17
Bass_GetVersion returns: 33820928
BASS.NET version: 2.4.17.5
Android device: Redmi K30 Pro, Android 12

If i replace 'BASSInit.BASS_DEVICE_AUDIOTRACK' with 'BASSInit.BASS_DEVICE_DEFAULT', no error occurs.
Thanks for any help.
« Last Edit: 11 Apr '24 - 16:06 by lfeng »

Ian @ un4seen

  • Administrator
  • Posts: 25778
Re: BASS_Init giving BASS_ERROR_UNKNOWN on Android
« Reply #1 on: 11 Apr '24 - 15:07 »
As you aren't using Java, I think the issue there is most likely that BASS doesn't have a JavaVM through which to access the AudioTrack class. BASS is usually given one via its JNI_OnLoad function, but I guess that isn't called by .Net? Does .Net give you access to its JavaVM? If so, there's a BASS_CONFIG_ANDROID_JAVAVM option that you can use with BASS_SetConfigPtr to pass it to BASS. I'm not sure BASS.Net currently includes the BASS_CONFIG_ANDROID_JAVAVM option, but if not, its value is 63 and you can use it something like this:

Code: [Select]
Bass.BASS_SetConfigPtr((BassConfig)63, javavm);

lfeng

  • Posts: 5
Re: BASS_Init giving BASS_ERROR_UNKNOWN on Android
« Reply #2 on: 11 Apr '24 - 16:05 »
As you aren't using Java, I think the issue there is most likely that BASS doesn't have a JavaVM through which to access the AudioTrack class. BASS is usually given one via its JNI_OnLoad function, but I guess that isn't called by .Net? Does .Net give you access to its JavaVM? If so, there's a BASS_CONFIG_ANDROID_JAVAVM option that you can use with BASS_SetConfigPtr to pass it to BASS. I'm not sure BASS.Net currently includes the BASS_CONFIG_ANDROID_JAVAVM option, but if not, its value is 63 and you can use it something like this:

Code: [Select]
Bass.BASS_SetConfigPtr((BassConfig)63, javavm);

Thank you Ian, it works :D

lfeng

  • Posts: 5
by the way, i found a similar issue: https://github.com/xamarin/xamarin-android/issues/7616, could be related with this problem.
happy coding :D

Ian @ un4seen

  • Administrator
  • Posts: 25778
If I'm reading that link right, Xamarin should call a native library's JNI_OnLoad function but doesn't in at least some cases? If so, is there something that the user or BASS.Net needs to do to have BASS's JNI_OnLoad function called? I see LoadLibrary mentioned there. Perhaps the Bass.LoadMe method (which uses LoadLibrary) will help?

lfeng

  • Posts: 5
Xamarin should call a native library's JNI_OnLoad function but doesn't in at least some cases?
looks like, i'm using LoadLibrary, it also works

If so, is there something that the user or BASS.Net needs to do to have BASS's JNI_OnLoad function called?
actually i have no idea, i'm new to Xamarin ;)

I see LoadLibrary mentioned there. Perhaps the Bass.LoadMe method (which uses LoadLibrary) will help?
wow it looks better than calling LoadLibrary :D i'll try it
« Last Edit: 19 Apr '24 - 05:13 by lfeng »

lfeng

  • Posts: 5
If I'm reading that link right, Xamarin should call a native library's JNI_OnLoad function but doesn't in at least some cases? If so, is there something that the user or BASS.Net needs to do to have BASS's JNI_OnLoad function called? I see LoadLibrary mentioned there. Perhaps the Bass.LoadMe method (which uses LoadLibrary) will help?

i got an error: error CS0117: 'Bass' does not contain a definition for 'LoadMe', however i found this method existing in the api document (Bass.Net.chm)
am i missing something?