-
streaming mp3
how do i stream an mp3 (downloading in chunks and playing)? i first downloaded a part of the file as bytearray, then converted it into inputStream using bytearrayinputstream. and then played it. but the player gives a start exception(it sucessfully realizes and prefetches). im testing my app in sony ericssion emulator, that suports mp3.
plz help me. point out whats wrong here:
the download function:
hcon = ( HttpConnection )Connector.open("any mp3 file url here");//<---
hcon.setRequestMethod(HttpConnection.GET);
stin=hcon.openInputStream();
InputStreamReader(hcon.openInputStream());
if (hcon.getResponseCode( ) == HttpConnection.HTTP_OK) {
ByteArrayOutputStream star = null;
byte stdata[]=new byte[500];
System.out.println("stream "+hcon.getHeaderField("content-type"));
//the content-type returned is "audio/mpeg"
int total = 0;
star = new ByteArrayOutputStream();
int ch;
System.out.println("length no");
while ((ch = stin.read()) != -1){System.out.println(ch);
System.out.println(stin.available());total++; System.out.println(total+" "+count);
star.write(ch);
if(total==500)break;//breaks if the bytearray has 500 entries
}
System.out.println("finished");
InputStream aa=new ByteArrayInputStream(star.toByteArray());//converting bytearray to inputstream
craze.PLY(aa);//the player class to plaay the inputstream
}
-
Without all the code and the hardware, its very hard to help.
Are you sure that the data is being sent correctly?
Can you send a small file, read it and compare it against what was sent to see if the communications is working correctly?
What is a "start exception"? Can you copy and post the full text of the error message here?