Start New Discussion within our Software Development Community

Hello everyone,

I have question about how AudioTrack instance should be used for streaming applications. Below my code example and some brief explation about code

... /* some work before */
InputStream in = client.getInputStream();

AudioTrack output_stream = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
                                                                 AudioFormat.ENCODING_PCM_8BIT, 8192, 
                                                                 AudioTrack.MODE_STREAM);
                          byte[] buffer = new byte[8192];                                       

                        int count;
                        while ((count = in.read(buffer)) != -1)
                            output_stream.write(buffer, 0, count);
                            output_stream.flush();

Now I am in my receiver class where receives sound data from sender class I want to use this sound to play as streaming mode, and in Android API we can use AudioTrack.MODE_STREAM I hear some sound in fact, but it is very bad, I just hear like "sizzle". Where could be problem, please help, thanks...

Problem is solved. Thanks. I had needed to change PCM_8BIT with PCM_16BIT and push the play() method in while loop, after flush() statement is executed.

This question has already been answered. Start a new discussion instead.