On Sunday, December 20, 2015 at 11:27:14 PM UTC-8, gjs wrote:
>
> Hi,
>
> Here's some examples of using AudioTrack
> http://www.programcreek.com/java-api-examples/index.php?api=android.media.AudioTrack
>
> Just be sure to run in a separate thread.
>
> Regards
>
Note that I did already say that I'd found multiple ways to do this, and I
was looking for advice on the actual best (or at least better) way to do
this, and you pointed me to a selection of choices, with no information on
tradeoffs.
In any case, I tried the first one (creating an AudioTrack and then playing
it), and wrapping it with a Runnable and a started Thread, and I heard no
sound from my device when the code executed.
If it matters, here's the method I ended up with:
private void playTone() {
new Thread(new Runnable() {
@Override
public void run() {
int minSize = AudioTrack.getMinBufferSize(8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);
AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, minSize,
AudioTrack.MODE_STREAM);
audioTrack.play();
}
}).start();
}
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/e6f449ee-433c-4410-8948-0d5900b8934f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.