Audio Play in Android through network.

All your problems with Audio, Video and Images.

Audio Play in Android through network.

Postby anshu » Thu Apr 07, 2011 9:34 am

Hi friends,

I am trying to play a media file(.wav) that I am receiving through network in Smaller chunks and using Audio Track I am playing. My Design look like.


My Android Application running as UDP server , I will initialize the buffer with proper minBufferSize and all other parameters according to media file.

My other Java Code convert media file in Byte array and every 20 miliseconds delay I am sending the 320 byte(try the other size also) to server.

Server receiving data put the data into track(write ) and play.

Now problem is that:

1. After stating the play , in some seconds playing data is shrinking. If I ll close the connection and again start it play proper and after some time it shrinks again. How to Avoid This shrinking of Data. Second thing if I want to some time extent to reinitialize my track. Is'nt any way there?

My Code snippet is like:

try {
int socket_port =9876 ;
int MAX_BUF=742;
aSocket = new DatagramSocket(socket_port);
byte[] buffer = new byte[MAX_BUF];
/****************track initialization*******************/
System.out.println(":Track Creation: a");

int bufferSize =AudioTrack.getMinBufferSize(8000,AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT);
System.out.println(":Track Creation: a"+bufferSize);

track = new AudioTrack(AudioManager.STREAM_MUSIC,8000,
bufferSize, AudioTrack.MODE_STREAM);

DatagramPacket request = new DatagramPacket(buffer,

byte[] audiobuffer=new byte[MAX_BUF];


//getting the data from Datagram Packet:
track.write(audiobuffer, 0, audiobuffer.length);;

try {
} catch (InterruptedException e) {
// TODO Auto-generated catch block


catch (SocketException e) {

System.out.println("Socket: " + e.getMessage());
catch (IOException e) {
System.out.println("IO: " + e.getMessage());



Give me some Guidance?

RE: why After some extent of time the paying data shrinked, If I want to reintialize the track , that sound elapsed, Can we reintialize the track after some time of extent
Once Poster
Once Poster
Posts: 1
Joined: Thu Apr 07, 2011 9:29 am


Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 27 guests