Audio player with buffer...

All your problems with Audio, Video and Images.

Audio player with buffer...

Postby ANDR_eas » Fri Oct 02, 2009 8:47 pm

Hi guys,
I created an app, which gets audio data from a server.
Then I store the data to a file on the sdcard and afterwards play it with the MediaPlayer...

This looks like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. String src = "http://xxx.xxx";
  3.  
  4. File f = new File("sdcard", "filename.mpeg");
  5.  
  6. URL url = new URL(src);
  7.  
  8. HttpURLConnection con = (HttpURLConnection) url.openConnection();
  9.  
  10. InputStream in = con.getInputStream();
  11.  
  12. FileOutputStream output = new FileOutputStream(f);
  13.  
  14. byte[] buffer = new byte[BUFFER_SIZE];
  15.  
  16. int read = 0;
  17.  
  18. do{
  19.  
  20.         read = in.read(buffer);
  21.  
  22.         output.write(buffer, 0, read);
  23.  
  24. } while(read>0);
  25.  
  26. in.close();
  27.  
  28.  
  29.  
  30. player = new MediaPlayer();
  31.  
  32. player.setDataSource(f.getAbsolutePath());
  33.  
  34. player.prepare();
  35.  
  36. player.start();
  37.  
  38.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


It works quite well.
But I'm searching a way to directly play the read data, without saving it.
As this is not PCM it doesn't work with AudioTrack.

Anybody an idea?
thanks for reading and hopefully helping :)
ANDR_eas
Freshman
Freshman
 
Posts: 3
Joined: Thu May 14, 2009 9:32 am

Top

Postby sachendra » Tue Oct 06, 2009 12:00 pm

You can create a uri of the url of the file. And can pass that uri in mediaplayer's constructor.
Sachendra Singh Rathore
s.sachendra@live.in
Android aplication developer
sachendra
Junior Developer
Junior Developer
 
Posts: 18
Joined: Wed Mar 18, 2009 12:25 pm
Location: Mumbai

Postby ANDR_eas » Tue Oct 06, 2009 4:10 pm

sachendra wrote:You can create a uri of the url of the file. And can pass that uri in mediaplayer's constructor.


Well, i knew that,
but we are talking about a stream.
So i have to read it out like this.
The question is: how can i play the data from the byte[] (MPEG coded) ?
ANDR_eas
Freshman
Freshman
 
Posts: 3
Joined: Thu May 14, 2009 9:32 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 24 guests