mirror of
https://github.com/danog/termux-api.git
synced 2024-11-30 04:19:20 +01:00
gets info for fast_mixer (#126)
This commit is contained in:
parent
d57169a97a
commit
a544de8c1b
38
app/src/main/java/com/termux/api/AudioAPI.java
Normal file
38
app/src/main/java/com/termux/api/AudioAPI.java
Normal file
@ -0,0 +1,38 @@
|
||||
package com.termux.api;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.util.JsonWriter;
|
||||
import android.media.AudioTrack;
|
||||
|
||||
import com.termux.api.util.ResultReturner;
|
||||
import com.termux.api.util.ResultReturner.ResultWriter;
|
||||
|
||||
|
||||
|
||||
public class AudioAPI {
|
||||
static void onReceive(TermuxApiReceiver apiReceiver, final Context context, Intent intent) {
|
||||
ResultReturner.returnData(apiReceiver, intent, new ResultReturner.ResultJsonWriter() {
|
||||
|
||||
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
String SampleRate = am.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
|
||||
String framesPerBuffer = am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
|
||||
String AudioUnprocessed = am.getProperty(AudioManager.PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED);
|
||||
int nativeoutput = AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC);
|
||||
int volume_level= am.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
int maxvolume_level = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
||||
public void writeJson(JsonWriter out) throws Exception {
|
||||
out.beginObject();
|
||||
out.name("PROPERTY_OUTPUT_SAMPLE_RATE").value(SampleRate);
|
||||
out.name("PROPERTY_OUTPUT_FRAMES_PER_BUFFER").value(framesPerBuffer);
|
||||
out.name("PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED").value(AudioUnprocessed);
|
||||
out.name("STREAM_MUSIC_VOLUME").value(volume_level);
|
||||
out.name("STREAM_MUSIC_MAXVOLUME").value(maxvolume_level);
|
||||
out.name("CURRENT_NATIVE_OUTPUT_SAMPLERATE").value(nativeoutput);
|
||||
out.endObject();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,10 @@ public class TermuxApiReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
switch (apiMethod) {
|
||||
case "BatteryStatus":
|
||||
case "AudioInfo":
|
||||
AudioAPI.onReceive(this, context, intent);
|
||||
break;
|
||||
case "BatteryStatus":
|
||||
BatteryStatusAPI.onReceive(this, context, intent);
|
||||
break;
|
||||
case "CameraInfo":
|
||||
|
Loading…
Reference in New Issue
Block a user