java - AudioTrack in MODE_STREAM has no sound -
i've been stuck on problem days. i'm @ stage i'm trying working example build from, can't reach point.
my question based on this example. i've included source (and solution) own code, , can see buffer being written to, no sound comes device. i'm struggling identify how debug further.
package com.example.audio; import com.example.r; import java.io.ioexception; import java.io.inputstream; import android.content.context; import android.media.audioformat; import android.media.audiomanager; import android.media.audiotrack; import android.util.log; public class synth { private static final string tag = synth.class.getsimplename(); private audiotrack audiotrack; private context context; public synth(context context) { this.context = context; int minbuffersize = audiotrack.getminbuffersize(22050, audioformat.channel_out_mono, audioformat.encoding_pcm_16bit); audiotrack = new audiotrack(audiomanager.stream_music, 22050, audioformat.channel_out_mono, audioformat.encoding_pcm_16bit, minbuffersize, audiotrack.mode_stream); } public void playsound() { audiotrack.play(); int = 0; int buffersize = 512; byte [] buffer = new byte[buffersize]; inputstream inputstream = context.getresources().openrawresource(r.raw.mysample); try { int writes = 0; while((i = inputstream.read(buffer)) != -1) { writes++; audiotrack.write(buffer, 0, i); } log.d(tag, "wrote " + writes + " times." ); } catch (ioexception e) {e.printstacktrace();} try {inputstream.close();} catch (ioexception e) {e.printstacktrace();} } }
(to replicate project: make new project, include class, add audio mentioned below, create instance of synth
, fire playsound
public function)
obviously can't upload audio, or guarantee it's persistence in web folder, this tool generate wav file using (change sample rate 22.05khz , press 'download .wav file')
i realize stream_music
, mode_stream
seem out of place in example. using flags/mode because know need use audiotrack these modes later in development, , trying sound coming out of device moment.
can suggest debugging steps, or see problem playback is? appreciated.
i've determined problem had when first raised question. helps other people out there...
as turns out, app wasn't playing audio @ time when adjusting volume, volume maxed system/ringtone volumes, , not 'music, video games, , other media' volume, muted.
Comments
Post a Comment