[Solved] BASS_Init giving BASS_ERROR_UNKNOWN on Android

Started by lfeng, 11 Apr '24 - 04:45

lfeng

Hi,
I got BASS_Init failure with BASS_ERROR_UNKNOWN on Android (using BASS.NET library), see below code:
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.

Ian @ un4seen

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:

Bass.BASS_SetConfigPtr((BassConfig)63, javavm);

lfeng

Quote from: Ian @ un4seen on 11 Apr '24 - 15:07As 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:

Bass.BASS_SetConfigPtr((BassConfig)63, javavm);

Thank you Ian, it works :D

lfeng


Ian @ un4seen

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

Quote from: Ian @ un4seen on 12 Apr '24 - 12:31Xamarin 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

Quote from: Ian @ un4seen on 12 Apr '24 - 12:31If 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 ;)

Quote from: Ian @ un4seen on 12 Apr '24 - 12:31I 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

lfeng

Quote from: Ian @ un4seen on 12 Apr '24 - 12:31If 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?

AndyMK

Same problem here. I want to place the BASS dll's in a folder and use this method to load the libs. In dotNet, the method does not exist.

AndyMK

Ok, i just figured out, it's only available for the full api. I am using core.