From 627af82189d25db0a10c3b245023e3b37a1025cd Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Sun, 24 Nov 2024 15:02:43 -0800 Subject: [PATCH] AndroidAudioForJSyn: update AudioTrack constructor Use Builders instead of the old deprecated APIs. Author: lespin --- .../devices/android/AndroidAudioForJSyn.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/android/com/jsyn/devices/android/AndroidAudioForJSyn.java b/android/com/jsyn/devices/android/AndroidAudioForJSyn.java index 2d17b0c..ce88a21 100644 --- a/android/com/jsyn/devices/android/AndroidAudioForJSyn.java +++ b/android/com/jsyn/devices/android/AndroidAudioForJSyn.java @@ -15,6 +15,8 @@ */ package com.jsyn.devices.android; import java.util.ArrayList; + +import android.media.AudioAttributes; import android.os.Process; import android.media.AudioFormat; import android.media.AudioManager; @@ -87,10 +89,21 @@ public void start() { // LOGGER.debug("Audio minBufferSize = " + minBufferSize); bufferSize = (3 * (minBufferSize / 2)) & ~3; // LOGGER.debug("Audio bufferSize = " + bufferSize); - audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, frameRate, - AudioFormat.CHANNEL_OUT_STEREO, - AudioFormat.ENCODING_PCM_FLOAT, bufferSize, - AudioTrack.MODE_STREAM); + AudioAttributes audioAttributes = new AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_MEDIA) + .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) + .build(); + AudioFormat audioFormat = new AudioFormat.Builder() + .setSampleRate(frameRate) + .setEncoding(AudioFormat.ENCODING_PCM_FLOAT) + .setChannelMask(AudioFormat.CHANNEL_OUT_STEREO) + .build(); + audioTrack = new AudioTrack( + audioAttributes, + audioFormat, + bufferSize, + AudioTrack.MODE_STREAM, + 0); audioTrack.play(); } /** Grossly inefficient. Call the array version instead. */