这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@tomty89
Copy link
Contributor

@tomty89 tomty89 commented Feb 8, 2018

No description provided.

@fornwall fornwall merged commit 9552c41 into termux:master Mar 22, 2018
@fornwall
Copy link
Member

Thanks!

@its-pointless
Copy link
Contributor

its-pointless commented Mar 23, 2018

Why i didn't write it this way in the first place
termux-api/app/src/main/java/com/termux/api/AudioAPI.java:55: error: cannot find symbol out.name("AUDIOTRACK_BUFFER_SIZE_IN_FRAMES").value(bs);

What i think is happening is that the same code compiles differently at different api levels.

@its-pointless
Copy link
Contributor

its-pointless commented Mar 23, 2018 via email

@tomty89
Copy link
Contributor Author

tomty89 commented Mar 23, 2018

Wait a second is the error you posted build time error or runtime error (that seen only on older device)?

Does it change anything if you keep the structure but just change getBufferSizeInFrames to getSampleRate?

@its-pointless
Copy link
Contributor

its-pointless commented Mar 23, 2018

build time
and it makes no difference
I literally tried using this structure but it didn't compile.

@tomty89
Copy link
Contributor Author

tomty89 commented Mar 24, 2018

$ tree -a com/
com/
└── termux
    └── api
        ├── AudioAPI.java
        ├── TermuxApiReceiver.java
        └── util
            ├── ResultReturner.java
            ├── TermuxApiLogger.java
            └── TermuxApiPermissionActivity.java

3 directories, 5 files
$ cat com/termux/api/TermuxApiReceiver.java
package com.termux.api;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.termux.api.util.TermuxApiLogger;

public class TermuxApiReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String apiMethod = intent.getStringExtra("api_method");
        if (apiMethod == null) {
            TermuxApiLogger.error("Missing 'api_method' extra");
            return;
        }

        switch (apiMethod) {
            case "AudioInfo":
                AudioAPI.onReceive(this, context, intent);
                break;
            default:
                TermuxApiLogger.error("Unrecognized 'api_method' extra: '" + apiMethod + "'");
        }
    }

}
$ git diff com/termux/api/AudioAPI.java
diff --git a/app/src/main/java/com/termux/api/AudioAPI.java b/app/src/main/java/com/termux/api/AudioAPI.java
index acf87ed..7e13c2d 100644
--- a/app/src/main/java/com/termux/api/AudioAPI.java
+++ b/app/src/main/java/com/termux/api/AudioAPI.java
@@ -23,6 +23,7 @@ public class AudioAPI {
         final boolean bluetootha2dp = am.isBluetoothA2dpOn();
         final boolean wiredhs = am.isWiredHeadsetOn();
         final int nativeoutput = AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC);
+       int _bs = 0;
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             AudioTrack at = new AudioTrack(
                 new AudioAttributes.Builder()
@@ -34,11 +35,12 @@ public class AudioAPI {
                 AudioTrack.MODE_STREAM,
                 AudioManager.AUDIO_SESSION_ID_GENERATE
             );
-            final int bs = at.getBufferSizeInFrames();
+            _bs = at.getBufferSizeInFrames();
             //final int bc = at.getBufferCapacityInFrames(); only available api 24 and up and apparently
             // always returns same value as the initial getbuffersizeinframes.
             at.release();
         }
+       final int bs = _bs;

         ResultReturner.returnData(apiReceiver, intent, new ResultReturner.ResultJsonWriter() {
             public void writeJson(JsonWriter out) throws Exception {
$ ecj com/
----------
1. WARNING in /data/data/com.termux/files/home/termux-api/app/src/main/java/com/termux/api/AudioAPI.java (at line 23)
        final boolean bluetootha2dp = am.isBluetoothA2dpOn();
                                         ^^^^^^^^^^^^^^^^^^^
The method isBluetoothA2dpOn() from the type AudioManager is deprecated
----------
2. WARNING in /data/data/com.termux/files/home/termux-api/app/src/main/java/com/termux/api/AudioAPI.java (at line 24)
        final boolean wiredhs = am.isWiredHeadsetOn();
                                   ^^^^^^^^^^^^^^^^^^
The method isWiredHeadsetOn() from the type AudioManager is deprecated
----------
2 problems (2 warnings)
$

Not sure if it's the best way coz it still looks a bit stupid to me, but at least it should work for now.

@tomty89
Copy link
Contributor Author

tomty89 commented Mar 24, 2018

Sorry for not doing a build test before making the PR btw. Don't have a PC and didn't thought of testing it like this on Termux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants