how can I create MediaPlayer from InputStream

All your problems with Audio, Video and Images.

how can I create MediaPlayer from InputStream

Postby logtoavi » Sun May 03, 2009 7:48 am

I am making a class javax.microedition.media.Manager and i have to implement a method

public static Player createPlayer( java.io.InputStream ins, String type ) throws IOException, MediaException
{
// Body
}

So i have to create MediaPlayer from InputStream. how can i do this because there is no method in MediaPlayer class. :( :(


Thanks in advance
Thanks and Regards
Avishek Kumar
logtoavi
Freshman
Freshman
 
Posts: 9
Joined: Wed Dec 17, 2008 11:30 am
Location: Noida

Top

Creating MediaPlayer with Input stream

Postby chandra431 » Mon Aug 24, 2009 5:55 am

Hi,

I have similar requirement. Can any one suggest how to create Audio player with Input stream or byte array.

It will be a great help if any one can suggest any work around.

Thanks in Advance,
Purnachandra.
chandra431
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Aug 24, 2009 5:50 am

Postby AndSmash » Thu Sep 03, 2009 7:40 am

I don't know if you still need help with this, but this was an issue that I came across before. Here is how I would do it
-Read InputStream into a temporary file on the device using FileOutputStream.
-Set MediaPlayer to the path of that temporary file.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. InputStream yourStream;
  3.  
  4. MediaPlayer mp = new MediaPlayer();
  5.  
  6. File temp = new File(getCacheDir(),"temp.dat");
  7.  
  8. temp.createNewFile();
  9.  
  10. String tempPath = temp.getAbsolutePath();
  11.  
  12.                                        
  13.  
  14. FileOutputStream out = new FileOutputStream(temp);
  15.  
  16. byte buf[] = new byte[128];
  17.  
  18. do{
  19.  
  20.    int numread = yourStream.read(buf);
  21.  
  22.    if(numread <= 0) break;
  23.  
  24.    out.write(buf,0,numread);
  25.  
  26.    } while(true);
  27.  
  28. mp.setDataSource(tempPath);
  29.  
  30. mp.prepare();
  31.  
  32.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
AndSmash
Freshman
Freshman
 
Posts: 4
Joined: Sat Aug 08, 2009 5:51 am

Postby Zeba Momin » Tue Nov 17, 2009 11:10 am

Using this solution u will hav a copy of d media on d device in d temp.dat file.
I want to pass a stream or an byte array to d media player....while i continue to fill it simultaneously.
How can i achieve dis?
R der ne 3rd party media players in android which might help me do dis?
Thank you.

AndSmash wrote:I don't know if you still need help with this, but this was an issue that I came across before. Here is how I would do it
-Read InputStream into a temporary file on the device using FileOutputStream.
-Set MediaPlayer to the path of that temporary file.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. InputStream yourStream;
  2. MediaPlayer mp = new MediaPlayer();
  3. File temp = new File(getCacheDir(),"temp.dat");
  4. temp.createNewFile();
  5. String tempPath = temp.getAbsolutePath();
  6.                                        
  7. FileOutputStream out = new FileOutputStream(temp);
  8. byte buf[] = new byte[128];
  9. do{
  10.    int numread = yourStream.read(buf);
  11.    if(numread <= 0) break;
  12.    out.write(buf,0,numread);
  13.    } while(true);
  14. mp.setDataSource(tempPath);
  15. mp.prepare();
  16.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
Zeba Momin
Developer
Developer
 
Posts: 49
Joined: Thu Sep 17, 2009 6:53 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 28 guests