Author Topic: BASS for Android  (Read 680390 times)

MPage

  • Posts: 4
Re: BASS for Android
« Reply #1675 on: 24 Jan '20 - 12:22 »
:'(  :'(  :'(  I'm developing with Delphi 10.3.3 an app for Android. Compiling for Android 32-bits with Android SDK 25.2.5.

Please help me with 2 issues that I cannot yet resolve:

1) What libbass.so I need to have for above versions of development?  ???
  The options:
      armeabi\libbass.so size 248,304 bytes
      armeabi-v7a\libbass.so size 226,712 bytes
      arm64-v8a\libbass.so size 317,096 bytes - compilation error
      x86\libbass.so size 324,908 bytes - compilation error
      x86_64\libbass.so 309,104 bytes - compilation error

2) Where I can download a latest and correct bass.pass that is supports Android (and Windows too)?
Can someone attach it here?  ???

I tried both "armeabi\libbass.so" and "armeabi-v7a\libbass.so" - my test project apk building successfully. But when I trying to run on Android (9), it just crashes immediately after splash screen.  Test project APK is an empty form with only one thing added in code "use Bass;"
I spent hours and hours, but can't find a solution. Or "bass.so" is wrong, or "bass.pas" is wrong...

Attached bass.pas file that I use. It is a file from "Bass Windows" archive, where I added just these lines under 'type' section:
    PAnsiChar = system.MarshaledAString;
    AnsiChar = system.Byte;



Hi,

I'm developing with Delphi 10.2.3.
I also tried this new version of BASS for Android, but with everything I tried, I just got error messages or at the end, the the app just showed the splash screen.

I went back to the version of March 2019 and everything is fine again. But I also have to mention that the "bass.pas" also had to be "adjusted" to work with Android (uses statements and variable types).
I use "armeabi\libbass.so", which has to be deployed to "library/lib/armeabi-v7a/" in Delphi as the "Remote-Path". My app runs on various devices (Galaxy Note 3, Galaxy S7 Edge, Galaxy S10, Leagoo S10, Galaxy S5 mini...) and different Android versions (5.x to 10)

MPage
« Last Edit: 24 Jan '20 - 12:26 by MPage »

Ian @ un4seen

  • Administrator
  • Posts: 22833
Re: BASS for Android
« Reply #1676 on: 24 Jan '20 - 17:00 »
1) What libbass.so I need to have for above versions of development?  ???
  The options:
      armeabi\libbass.so size 248,304 bytes
      armeabi-v7a\libbass.so size 226,712 bytes
      arm64-v8a\libbass.so size 317,096 bytes - compilation error
      x86\libbass.so size 324,908 bytes - compilation error
      x86_64\libbass.so 309,104 bytes - compilation error

You would normally include all of them, or at least the ones that you want to support. You can leave out "armeabi" unless you want to support very old devices. If you want to include only one then I would suggest making that "armeabi-v7a" (arm64-v8a devices also support armeabi-v7a).

2) Where I can download a latest and correct bass.pass that is supports Android (and Windows too)?
Can someone attach it here?  ???

The latest BASS.PAS file can be taken from the Windows or Linux BASS packages. I guess it may need some modification for Android, but I'm not familiar with Delphi on Android, so I'm not sure about that.

I tried both "armeabi\libbass.so" and "armeabi-v7a\libbass.so" - my test project apk building successfully. But when I trying to run on Android (9), it just crashes immediately after splash screen.  Test project APK is an empty form with only one thing added in code "use Bass;"

To hopefully help identify what the problem is, please post the Logcat output from the crash.

I use "armeabi\libbass.so", which has to be deployed to "library/lib/armeabi-v7a/" in Delphi as the "Remote-Path". My app runs on various devices (Galaxy Note 3, Galaxy S7 Edge, Galaxy S10, Leagoo S10, Galaxy S5 mini...) and different Android versions (5.x to 10)

If you're going to include libraries for only one architecture in your app, I would suggest using "armeabi-v7a" rather than "armeabi". The armeabi BASS version does not include floating-point support (eg. BASS_SAMPLE_FLOAT flag) or NEON optimizations.

baylung

  • Posts: 2
Re: BASS for Android
« Reply #1677 on: 25 Jan '20 - 15:06 »

Hi,

I'm developing with Delphi 10.2.3.
I also tried this new version of BASS for Android, but with everything I tried, I just got error messages or at the end, the the app just showed the splash screen.

I went back to the version of March 2019 and everything is fine again. But I also have to mention that the "bass.pas" also had to be "adjusted" to work with Android (uses statements and variable types).
I use "armeabi\libbass.so", which has to be deployed to "library/lib/armeabi-v7a/" in Delphi as the "Remote-Path". My app runs on various devices (Galaxy Note 3, Galaxy S7 Edge, Galaxy S10, Leagoo S10, Galaxy S5 mini...) and different Android versions (5.x to 10)

MPage

Thank you very much for your reply and help!
Now I can build APK and run on Android (and NOX android emulator)! I was so happy :)
But now I have another problem that I cannot solve with Android app.
Maybe you can guide me how to fix, or what is the right way to do? ???

This is what I'm doing in my Delphi code for Android app:

1) Added my 'wav' and 'mp3' files as resources in "Delphi Project/Resources and Images"
2) in code I'm saving all these resources locally, similar to this:
Code: [Select]
InStream := TResourceStream.Create(HInstance, 'sound_1_resource_name', RT_RCDATA);
strFileName := TPath.Combine(TPath.GetDocumentsPath, 'sound_1.wav')
InStream.SaveToFile(strFileName);
3) BASS initialization is Ok
Code: [Select]
BASS_Init(-1, 44100, 0, 0, nil)4) Trying to load these files as samples, and here I have problem:
Code: [Select]
f := PChar(strFileName);
SampleHandle := BASS_SampleLoad(False, f, 0, 0, 5, BASS_SAMPLE_OVER_POS);

SampleHandle is always 0, meaning have error. And BASS_ErrorGetCode returns:

Real Android device (Android 9, Huawei P30): always error code 2, BASS_ERROR_FILEOPEN - cannot load the file.
On NOX emulator: always error code 41, BASS_ERROR_FILEFORM - wrong file format (I tried many different wav and mp3)

Can you please advise me why that is BASS_ERROR_FILEOPEN happening on Android device?
Maybe need some special system permissions, or settings at BASS?

PS/ Saving PNG and JPG files from app resources to local storage and opening them in App I'm doing fine, no issues. But with BASS BASS_SampleLoad this is does not working...

MPage

  • Posts: 4
Re: BASS for Android
« Reply #1678 on: 25 Jan '20 - 17:56 »

Hi,

I'm developing with Delphi 10.2.3.
I also tried this new version of BASS for Android, but with everything I tried, I just got error messages or at the end, the the app just showed the splash screen.

I went back to the version of March 2019 and everything is fine again. But I also have to mention that the "bass.pas" also had to be "adjusted" to work with Android (uses statements and variable types).
I use "armeabi\libbass.so", which has to be deployed to "library/lib/armeabi-v7a/" in Delphi as the "Remote-Path". My app runs on various devices (Galaxy Note 3, Galaxy S7 Edge, Galaxy S10, Leagoo S10, Galaxy S5 mini...) and different Android versions (5.x to 10)

MPage

Thank you very much for your reply and help!
Now I can build APK and run on Android (and NOX android emulator)! I was so happy :)
But now I have another problem that I cannot solve with Android app.
Maybe you can guide me how to fix, or what is the right way to do? ???

This is what I'm doing in my Delphi code for Android app:

1) Added my 'wav' and 'mp3' files as resources in "Delphi Project/Resources and Images"
2) in code I'm saving all these resources locally, similar to this:
Code: [Select]
InStream := TResourceStream.Create(HInstance, 'sound_1_resource_name', RT_RCDATA);
strFileName := TPath.Combine(TPath.GetDocumentsPath, 'sound_1.wav')
InStream.SaveToFile(strFileName);
3) BASS initialization is Ok
Code: [Select]
BASS_Init(-1, 44100, 0, 0, nil)4) Trying to load these files as samples, and here I have problem:
Code: [Select]
f := PChar(strFileName);
SampleHandle := BASS_SampleLoad(False, f, 0, 0, 5, BASS_SAMPLE_OVER_POS);

SampleHandle is always 0, meaning have error. And BASS_ErrorGetCode returns:

Real Android device (Android 9, Huawei P30): always error code 2, BASS_ERROR_FILEOPEN - cannot load the file.
On NOX emulator: always error code 41, BASS_ERROR_FILEFORM - wrong file format (I tried many different wav and mp3)

Can you please advise me why that is BASS_ERROR_FILEOPEN happening on Android device?
Maybe need some special system permissions, or settings at BASS?

PS/ Saving PNG and JPG files from app resources to local storage and opening them in App I'm doing fine, no issues. But with BASS BASS_SampleLoad this is does not working...

Hi!

First, I want to ask what you want to do with the sound files and your app. Is it something like a music player?
In some of my apps I also have to distribute files with the Android app. I think, a much better way is to pack them into a ZIP file and provide them via the "Project deployment manager". After the APK is installed on your device, you could unpack and save the files to the path you would like to have them - for example in "/storage/emulated/0/Android/data/YOUR_APPLICATION/files". This would be ".\assets\" as the "Remote Path" in the deployment manager.
You also can store/save/extract them in a "user defined" folder in "/storage/emulated/0". With this you also can check if everything is fine on the device with a filebrowser app or at the connected PC. (your device doesn't have to be rooted for this access).

This is a function with which I play a file on an Android device with one of my apps:

Code: [Select]
function TMainform.PlayFile(strFilename: String): Boolean;
var
  ResultCode: Integer;

begin
  Result := false;
  ResultCode := 0;
  BASS_ChannelStop(FActiveChannel);
  BASS_StreamFree(FActiveChannel);
  FActiveChannel := 0;

  //Create stream
  FActiveChannel := BASS_StreamCreateFile(FALSE, pchar(strFilename),
                    0, 0, 0 {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});

  if FActiveChannel = 0 then
  begin
    FActiveChannel := BASS_MusicLoad(False, PChar(strFilename), 0, 0,
                      BASS_MUSIC_RAMPS or BASS_MUSIC_POSRESET or
                      BASS_MUSIC_PRESCAN {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF}, 0);

    if (FActiveChannel = 0) then
    begin
      ResultCode := Bass_ErrorGetCode;
      Result := false;
      Exit;

    end;

  end;

  BASS_ChannelPlay(FActiveChannel , True);
  BASS_ChannelSetPosition(FActiveChannel, 0, BASS_POS_BYTE);
  Result := true;

end;


"FActiveChannel" if of type HSTREAM, but I think you know that. ;-)


Regards, MPage

wangbang

  • Posts: 4
Re: BASS for Android
« Reply #1679 on: 10 Feb '20 - 06:41 »
When i use   Bassmidi      boolean b = BASSMIDI.BASS_MIDI_StreamSetFilter(chan, false, MIDIFILTER, null);  APP  is crash   but Playing sf2 files is OK

    BASSMIDI.MIDIFILTERPROC MIDIFILTER = new BASSMIDI.MIDIFILTERPROC() {
        @Override
        public boolean MIDIFILTERPROC(int handle, int track, BASSMIDI.BASS_MIDI_EVENT event, boolean seeking, Object user) {
            BASSMIDI.BASS_MIDI_EVENT event1 = event;

            return true;
        }
    };


And  i dont load 

   BASS.BASS_PluginLoad(libpath + "/libbassflac.so", 0);
   BASS.BASS_PluginLoad(libpath + "/libbasswv.so", 0);



crash report:

JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.un4seen.bass.BASSMIDI$BASS_MIDI_EVENT" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib, /system/product/lib, /system/lib, /system/product/lib]]
2020-02-10 14:36:53.006 17846-17909/com.tuolu.drum A/com.tuolu.drum: java_vm_ext.cc:570]   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:230)
2020-02-10 14:36:53.006 17846-17909/com.tuolu.drum A/com.tuolu.drum: java_vm_ext.cc:570]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
2020-02-10 14:36:53.006 17846-17909/com.tuolu.drum A/com.tuolu.drum: java_vm_ext.cc:570]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
2020-02-10 14:36:53.006 17846-17909/com.tuolu.drum A/com.tuolu.drum: java_vm_ext.cc:570]
2020-02-10 14:36:53.006 17846-17909/com.tuolu.drum A/com.tuolu.drum: java_vm_ext.cc:570]     in call to GetMethodID

Ian @ un4seen

  • Administrator
  • Posts: 22833
Re: BASS for Android
« Reply #1680 on: 10 Feb '20 - 15:07 »
Are you using ProGuard (or similar) to obfuscate your Java code? If so, make sure you exclude the BASS classes from that. Instructions for ProGuard can be found in the first post.

wangbang

  • Posts: 4
Re: BASS for Android
« Reply #1681 on: 11 Feb '20 - 02:24 »
I used debug mode,but  is  targetsdk 28,Is the jni method declaration wrong? I can find BASSMIDIEVENT through reflection in the program

wangbang

  • Posts: 4
Re: BASS for Android
« Reply #1682 on: 11 Feb '20 - 02:32 »
In addition, I used Androidx to build the application. I want to get the events in the midi file in real time. In addition to setFilter, what should I do?

Ian @ un4seen

  • Administrator
  • Posts: 22833
Re: BASS for Android
« Reply #1683 on: 11 Feb '20 - 15:31 »
Is BASSMIDI working in your app if you don't use any classes from it, eg. just calling BASS_MIDI_StreamCreateFile? If so, check that you have set ProGuard to leave all of the BASS classes alone. If you have no luck with that, you could also try adding a "@Keep" line just before the "public class BASSMIDI" line in the BASSMIDI.java file.

nelson13

  • Posts: 3
Re: BASS for Android
« Reply #1684 on: 18 Feb '20 - 04:11 »
Hi how are you?
bass Android is not working with ftp links,Is it a known issue?

BASS_ERROR_HANDLE

I am using Android Studio

Thanks
« Last Edit: 18 Feb '20 - 14:41 by nelson13 »

wangbang

  • Posts: 4
Re: BASS for Android
« Reply #1685 on: 18 Feb '20 - 07:24 »
How do I mix audio synthesis files? Now I can only wait for channelPlay to finish mixing before I can successfully mix them. Can I mix them in advance without playing?

Code: [Select]
        if (!BASS.BASS_Init(-1, 44100, 0)) {
            return;
        }
        BASS.BASS_SetConfig(BASSmix.BASS_CONFIG_MIXER_BUFFER,50000*10);
        BASS.BASS_SetConfig(BASS.BASS_CONFIG_BUFFER,5000);
        BASS.BASS_SetConfig( BASSenc.BASS_CONFIG_ENCODE_QUEUE,0);

        mixer = BASSmix.BASS_Mixer_StreamCreate(44100, 1, BASS.BASS_STREAM_DECODE|BASSmix.BASS_MIXER_END);

        int temporation1 = BASS.BASS_StreamCreateFile(temp1, 0, 0, BASS.BASS_STREAM_DECODE);
        int temporation2 = BASS.BASS_StreamCreateFile(temp2, 0, 0, BASS.BASS_STREAM_DECODE);

        BASS.BASS_CHANNELINFO info = new BASS.BASS_CHANNELINFO();
        boolean b = BASS.BASS_ChannelGetInfo(temporation1, info);
        mixer = BASSmix.BASS_Mixer_StreamCreate(info.freq, info.chans, BASSmix.BASS_MIXER_NONSTOP|BASSmix.BASS_MIXER_BUFFER);
        BASSmix.BASS_Mixer_StreamAddChannel(mixer,temporation1,BASSmix.BASS_MIXER_NORAMPIN);
        BASSmix.BASS_Mixer_StreamAddChannel(mixer,temporation2,BASSmix.BASS_MIXER_NORAMPIN);
//        BASS.BASS_ChannelPlay(mixer, false); // start it
//        BASS.BASS_Update(200);
//        String temp3     = test + "/360/"+"HappyRecordResult.mp3";
//        int i = BASSenc_MP3.BASS_Encode_MP3_StartFile(mixer, null, BASSenc.BASS_ENCODE_LIMIT,temp3 );
//        int i2 = BASS.BASS_ErrorGetCode();

Ian @ un4seen

  • Administrator
  • Posts: 22833
Re: BASS for Android
« Reply #1686 on: 18 Feb '20 - 17:38 »
bass Android is not working with ftp links,Is it a known issue?

BASS_ERROR_HANDLE

FTP should be supported. Please give a URL that you are having the problem with, to have a look at.

How do I mix audio synthesis files? Now I can only wait for channelPlay to finish mixing before I can successfully mix them. Can I mix them in advance without playing?

To process the mix without playing, you need to set the BASS_STREAM_DECODE flag (and BASS_MIXER_END) on the mixer and then repeatedly call BASS_ChannelGetData to process it until you reach the end. Your code could be modified like this:

Code: [Select]
        int temporation1 = BASS.BASS_StreamCreateFile(temp1, 0, 0, BASS.BASS_STREAM_DECODE);
        int temporation2 = BASS.BASS_StreamCreateFile(temp2, 0, 0, BASS.BASS_STREAM_DECODE);

        BASS.BASS_CHANNELINFO info = new BASS.BASS_CHANNELINFO();
        boolean b = BASS.BASS_ChannelGetInfo(temporation1, info);
        mixer = BASSmix.BASS_Mixer_StreamCreate(info.freq, info.chans, BASS.BASS_STREAM_DECODE|BASSmix.BASS_MIXER_END);
        BASSmix.BASS_Mixer_StreamAddChannel(mixer,temporation1,BASSmix.BASS_MIXER_NORAMPIN);
        BASSmix.BASS_Mixer_StreamAddChannel(mixer,temporation2,BASSmix.BASS_MIXER_NORAMPIN);
        String temp3     = test + "/360/"+"HappyRecordResult.mp3";
        int i = BASSenc_MP3.BASS_Encode_MP3_StartFile(mixer, null, 0,temp3 );
       
// processing loop
ByteBuffer buffer = ByteBuffer.allocateDirect(20000); // processing buffer
while (true) {
int got = BASS.BASS_ChannelGetData(mixer, buffer, 20000); // process the mixer
if (got < 0) break; // end or error
}

BASSenc.BASS_Encode_Stop(mixer);

Note at least the "processing loop" part should be in a worker thread (not the main thread).

nelson13

  • Posts: 3
Re: BASS for Android
« Reply #1687 on: 18 Feb '20 - 18:07 »
bass Android is not working with ftp links,Is it a known issue?

BASS_ERROR_HANDLE

FTP should be supported. Please give a URL that you are having the problem with, to have a look at.
I sent the URL by private message.

Ian @ un4seen

  • Administrator
  • Posts: 22833
Re: BASS for Android
« Reply #1688 on: 19 Feb '20 - 14:42 »
Ah, it looks like the issue there is that BASS isn't currently decoding the filename (eg. converting %20 to a space) before sending it to the FTP server. Try using Android's URLDecoder class on the URL:

Code: [Select]
stream = BASS.BASS_StreamCreateURL(URLDecoder.decode(url), ...);

nelson13

  • Posts: 3
Re: BASS for Android
« Reply #1689 on: 19 Feb '20 - 15:35 »
It worked perfect! Thank you very much  :D

Ian @ un4seen

  • Administrator
  • Posts: 22833
Re: BASS for Android
« Reply #1690 on: 20 Feb '20 - 15:38 »
Great. BASS should really be decoding the URL itself (it does so on Windows/OSX/iOS), so here's an update that should fix that:

   www.un4seen.com/stuff/bass-android-test.zip

ekstro

  • Posts: 8
Re: BASS for Android
« Reply #1691 on: 24 Feb '20 - 13:43 »
How we can enable HLS adaptive bitrate streaming? Is it supported?

Ian @ un4seen

  • Administrator
  • Posts: 22833
Re: BASS for Android
« Reply #1692 on: 24 Feb '20 - 15:49 »
BASSHLS doesn't currently support switching bitrate mid-playback. What you can do is limit what bitrate BASSHLS will request via the BASS_CONFIG_HLS_BANDWIDTH option, eg. download the master playlist to see what bitrates are available and set that according to which you want to receive. Note you will need to call BASS_StreamCreateURL again to change bitrate, so it's unlikely to be a smooth transition if you switch mid-playback. You can check what master playlist entry (if any) an existing stream is using from its BASS_TAG_HLS_STREAMINF tag.

elan

  • Posts: 45
Re: BASS for Android
« Reply #1693 on: 6 Mar '20 - 19:35 »
Please see if you can still reproduce the problem with this latest build:

   www.un4seen.com/stuff/bass-android-test.zip

If it does still happen then I will probably need to send you a debug version to get more info.

FWIW, we still see a similar issue (play ⇢ pause ⇢ play not actually resuming) when using AAudio. The behavior improved greatly with the latest version (presumably this bug-fix), but even so, some our of testers can still reproduce the issue. We have been using OpenSL as it doesn't exhibit this issue.

elan

  • Posts: 45
Re: BASS for Android
« Reply #1694 on: 6 Mar '20 - 19:47 »
We've noticed that when using AAudio, audio ducking doesn't seem to work properly (e.g. Maps will speak over the app audio without ducking it). When using OpenSL, it all works properly and the audio is ducked by the system. Is there anything additional needed when using AAudio to get system ducking to work? Thanks!

hama

  • Guest
Fail to BASS_ChannelGetAttribute On Android API29
« Reply #1695 on: 8 Mar '20 - 14:05 »
My CODE:
Float value = new Float(0);
BASS.BASS_ChannelGetAttribute(chan, BASS_FX.BASS_ATTRIB_TEMPO, value);

Error LOG:
A/DEBUG: Abort message: 'JNI DETECTED ERROR IN APPLICATION: JNI SetFloatField called with pending exception java.lang.NoSuchFieldError: no "F" field "value" in class "Ljava/lang/Float;" or its superclasses
at boolean com.un4seen.bass.BASS.BASS_ChannelGetAttribute(int, int, java.lang.Float) (BASS.java:-2)


hama

  • Guest
When I connect to bluetooth earphone or usb earphone while playing music, It cannot play on earphone.
If earphone connected before bass init, It is no problem.
But connect after init, Bass not recognize the new earphone.

So I have to reInit like this,
        AudioManager am = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
        am.registerAudioDeviceCallback(new AudioDeviceCallback() {
            @Override
            public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
                reInitOnDeviceChanged(addedDevices);

                super.onAudioDevicesAdded(addedDevices);
            }

            @Override
            public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
                reInitOnDeviceChanged(removedDevices);

                super.onAudioDevicesRemoved(removedDevices);
            }
        }, null);

     private void reInitOnDeviceChanged(AudioDeviceInfo[] addedDevices) {
        boolean reInit = false;
        for(AudioDeviceInfo info:addedDevices) {
            switch(info.getType()) {
                case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP:
                case AudioDeviceInfo.TYPE_USB_HEADSET:
                    reInit = true;
                    break;
            }
        }

        if (reInit) {
            pause();
            int position = getPosition();
            BASS.BASS_Free();
            if (!BASS.BASS_Init(-1, 44100, 0)) {
                int errorNum = BASS.BASS_ErrorGetCode();
                Log.e("HAMA", "FAIL TO BASS INIT : " + errorNum);
            } else {
                makeChannel();
                setPosition(position);
            }
        }
    }


But best is to solve it internally.

JL

  • Guest
When I connect to bluetooth earphone or usb earphone while playing music, It cannot play on earphone.
If earphone connected before bass init, It is no problem.
But connect after init, Bass not recognize the new earphone.

This is my first post, so I'd just like to say thank you to Ian for the awesome library, it really works a treat :)

I'm unfortunately having the same headphone issue though.
On the phones I've tried, the audio routes perfectly on a Nexus 6P but doesn't work on a Pixel 2XL (Both are AAudio devices).
When I connect headphones (Bluetooth or wired) I see this in the logs on the Pixel 2XL but not on the 6P:

Code: [Select]
E/AAudioStream: setState(2) tried to set to 9 but already DISCONNECTED
D/AAudio: AAudioStream_close(s#2) called ---------------
E/AAudioStream: joinThread() - but has no thread
E/AAudioStream: setState(2) tried to set to 11 but already DISCONNECTED

If I disable AAudio on the Pixel 2XL it works fine but then the latency is obviously worse.

Only some AAudio devices seem to have this problem, so I hope there is another solution other than having to re-initialize BASS every time.

Ian @ un4seen

  • Administrator
  • Posts: 22833
Re: BASS for Android
« Reply #1698 on: 9 Mar '20 - 14:07 »
We've noticed that when using AAudio, audio ducking doesn't seem to work properly (e.g. Maps will speak over the app audio without ducking it). When using OpenSL, it all works properly and the audio is ducked by the system. Is there anything additional needed when using AAudio to get system ducking to work? Thanks!

AAudio doesn't appear to have any functions for controlling that, so I would expect it to behave the same as the other output APIs. Checking with the BASS examples, they don't seem to be ducking when using any of AAudio/OpenSLES/AudioTrack :) ... Perhaps the AudioFocusRequest class needs to be used:

   https://developer.android.com/guide/topics/media-apps/audio-focus

Are you already using that in your app? One thing that could perhaps be making a difference is that BASS will enable AAudio's low-latency mode by default, unless BASS_CONFIG_ANDROID_AAUDIO is set to 2 (or BASS_CONFIG_DEV_BUFFER is set to 50+).

My CODE:
Float value = new Float(0);
BASS.BASS_ChannelGetAttribute(chan, BASS_FX.BASS_ATTRIB_TEMPO, value);

Error LOG:
A/DEBUG: Abort message: 'JNI DETECTED ERROR IN APPLICATION: JNI SetFloatField called with pending exception java.lang.NoSuchFieldError: no "F" field "value" in class "Ljava/lang/Float;" or its superclasses
at boolean com.un4seen.bass.BASS.BASS_ChannelGetAttribute(int, int, java.lang.Float) (BASS.java:-2)

Android 10 doesn't allow native code to modify Float class values, so a new FloatValue class was added for use with BASS_ChannelGetAttribute (and others). If you don't see the FloatValue class in your BASS.java file then please redownload to get the latest version.

When I connect to bluetooth earphone or usb earphone while playing music, It cannot play on earphone.
If earphone connected before bass init, It is no problem.
But connect after init, Bass not recognize the new earphone.

So I have to reInit like this,
        AudioManager am = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
        am.registerAudioDeviceCallback(new AudioDeviceCallback() {
            @Override
            public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
                reInitOnDeviceChanged(addedDevices);

                super.onAudioDevicesAdded(addedDevices);
            }

            @Override
            public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
                reInitOnDeviceChanged(removedDevices);

                super.onAudioDevicesRemoved(removedDevices);
            }
        }, null);

     private void reInitOnDeviceChanged(AudioDeviceInfo[] addedDevices) {
        boolean reInit = false;
        for(AudioDeviceInfo info:addedDevices) {
            switch(info.getType()) {
                case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP:
                case AudioDeviceInfo.TYPE_USB_HEADSET:
                    reInit = true;
                    break;
            }
        }

        if (reInit) {
            pause();
            int position = getPosition();
            BASS.BASS_Free();
            if (!BASS.BASS_Init(-1, 44100, 0)) {
                int errorNum = BASS.BASS_ErrorGetCode();
                Log.e("HAMA", "FAIL TO BASS INIT : " + errorNum);
            } else {
                makeChannel();
                setPosition(position);
            }
        }
    }


But best is to solve it internally.

BASS_Start will try to reinitialize the output device if it has stopped working, so please try calling that instead of BASS_Free and BASS_Init. If that doesn't help, to check if the problem is AAudio specific, please see if it still happens when using OpenSLES or AudioTrack output instead of AAudio. You can use OpenSLES like this:

Code: [Select]
BASS.BASS_SetConfig(BASS.BASS_CONFIG_ANDROID_AAUDIO, 0);
BASS.BASS_Init(-1, 44100, 0);

And AudioTrack like this:

Code: [Select]
BASS.BASS_Init(-1, 44100, BASS.BASS_DEVICE_AUDIOTRACK);

I'm unfortunately having the same headphone issue though.
On the phones I've tried, the audio routes perfectly on a Nexus 6P but doesn't work on a Pixel 2XL (Both are AAudio devices).
When I connect headphones (Bluetooth or wired) I see this in the logs on the Pixel 2XL but not on the 6P:

Code: [Select]
E/AAudioStream: setState(2) tried to set to 9 but already DISCONNECTED
D/AAudio: AAudioStream_close(s#2) called ---------------
E/AAudioStream: joinThread() - but has no thread
E/AAudioStream: setState(2) tried to set to 11 but already DISCONNECTED

If I disable AAudio on the Pixel 2XL it works fine but then the latency is obviously worse.

Only some AAudio devices seem to have this problem, so I hope there is another solution other than having to re-initialize BASS every time.

When using AAudio output, BASS will automatically try to reinitialize the output device when it stops working, but perhaps it isn't immediately available in the Pixel 2XL case and so the reinitialization fails. Please try BASS_Start and see if that gets it going again.

JL

  • Guest
Re: BASS for Android
« Reply #1699 on: 9 Mar '20 - 16:25 »
When using AAudio output, BASS will automatically try to reinitialize the output device when it stops working, but perhaps it isn't immediately available in the Pixel 2XL case and so the reinitialization fails. Please try BASS_Start and see if that gets it going again.

I tried using BASS_Start() instead of BASS_Init() but I'm still getting the same behavior. When I plug in the headphones, the audio stops briefly but it doesn't route to the headphones.

Do you think the problem could be related to this?: https://github.com/google/oboe/blob/master/docs/notes/disconnect.md