Media player prepare error

All your problems with Audio, Video and Images.

Media player prepare error

Postby CFrancis » Fri Jan 09, 2009 8:03 am

I've seen a few references to this problem, but no answers as to what's going wrong. when i try to open an audio file i've downloaded i get this error:

01-09 01:46:38.261: ERROR/andriod.com.lastfm.StreamingMediaPlayer(519): java.io.IOException: Prepare failed.: status=0xFFFFFFFC

I'm using a modified version of the tutorial at http://blog.pocketjourney.com/2008/04/0 ... diaplayer/

I tried reverting to the original tutorial code, and i got the same error. I also tried using prepareAsync(), but that gave me the error:

01-09 01:46:38.911: ERROR/MediaPlayer(519): Attempt to call getDuration without a valid mediaplayer

and nothing is giving me any audio.


anyone have any idea what i'm doing wrong?


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void downloadAudioIncrement(String mediaUrl) throws IOException {
  2.  
  3.        
  4.  
  5.         URLConnection cn = new URL(mediaUrl).openConnection();  
  6.  
  7.         cn.connect();  
  8.  
  9.         InputStream stream = cn.getInputStream();
  10.  
  11.         if (stream == null) {
  12.  
  13.                 Log.e(getClass().getName(), "Unable to create InputStream for mediaUrl:" + mediaUrl);
  14.  
  15.         }
  16.  
  17.        
  18.  
  19.                 downloadingMediaFile = File.createTempFile("downloadingmedia", ".mp3", context.getCacheDir());//new File(context.getCacheDir(),"downloadingMedia_" + (counter++) + ".dat");
  20.  
  21.         FileOutputStream out = new FileOutputStream(downloadingMediaFile);  
  22.  
  23.         byte buf[] = new byte[16384];
  24.  
  25.         int totalBytesRead = 0, incrementalBytesRead = 0;
  26.  
  27.         do {
  28.  
  29.                 int numread = stream.read(buf);  
  30.  
  31.             if (numread <= 0)  
  32.  
  33.                 break;  
  34.  
  35.             out.write(buf, 0, numread);
  36.  
  37.             totalBytesRead += numread;
  38.  
  39.             incrementalBytesRead += numread;
  40.  
  41.             totalKbRead = totalBytesRead/1000;
  42.  
  43.             Log.d("BytesRead", String.valueOf(totalBytesRead));
  44.  
  45.             testMediaBuffer();
  46.  
  47.                 fireDataLoadUpdate();
  48.  
  49.         } while (validateNotInterrupted());  
  50.  
  51.  
  52.  
  53.         stream.close();
  54.  
  55.         if (validateNotInterrupted()) {
  56.  
  57.                 fireDataFullyLoaded();
  58.  
  59.         }
  60.  
  61.     }  
  62.  
  63.  
  64.  
  65. //
  66.  
  67. //.....
  68.  
  69. //
  70.  
  71.  
  72.  
  73. private void startMediaPlayer() {
  74.  
  75.         try {  
  76.  
  77.                 File bufferedFile = new File(context.getCacheDir(), "playingMedia" + (counter++) + ".dat");
  78.  
  79.                 moveFile(downloadingMediaFile,bufferedFile);
  80.  
  81.                
  82.  
  83.                 Log.e("Player",bufferedFile.length()+"");
  84.  
  85.                 Log.e("Player",bufferedFile.getAbsolutePath());
  86.  
  87.                
  88.  
  89.                 mediaPlayer = new MediaPlayer();
  90.  
  91.                 mediaPlayer.setDataSource(bufferedFile.getAbsolutePath());
  92.  
  93.                 mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  94.  
  95.                 mediaPlayer.prepare();
  96.  
  97.                
  98.  
  99.                 fireDataPreloadComplete();
  100.  
  101.                
  102.  
  103.         } catch (IOException e) {
  104.  
  105.                 Log.e(getClass().getName(), "Error initializing the MediaPlayer.", e);
  106.  
  107.                 return;
  108.  
  109.         }  
  110.  
  111.     }
  112.  
  113.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4
CFrancis
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Jan 09, 2009 7:09 am

Top

I have the same problem,

Postby drhu00 » Fri Jan 09, 2009 11:35 pm

I have the same problem, don't know how to fix it.
On eclipse emulator, sometime it is ok for the parepare, sometime's not.
But once create the apk file and install on standalone emulator, it always failed on the prepare call.
Strange Android.
drhu00
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Feb 12, 2008 6:41 pm

bug should be fixed,

Postby drhu00 » Sat Jan 10, 2009 12:32 am

please download here to you G1 Phone to see if it works
http://www.drhu.org:8080/StreamingRadioS1.apk
http://www.drhu.org:8080/StreamingRadioS1.apk

looks like a Stupid android bug or requiremet
drhu00
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Feb 12, 2008 6:41 pm

Re: Media player prepare error

Postby Khalyng » Wed Jan 14, 2009 6:30 pm

CFrancis wrote:...
downloadingMediaFile = File.createTempFile("downloadingmedia", ".mp3", context.getCacheDir());

...
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(bufferedFile.getAbsolutePath());
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepare();
...


you store your tempfile in the application cache directory and the problem is that the MediaPlayer doesn't have access rights to application directories.

Instead you should passing a FileDescriptor to your MediaPlayer with setDataSource(FileDescriptor fd).

Something like this:
...
FileInputStream fis = new FileInputStream(bufferedFile);
FileDescriptor fd = fis.getFD();
mediaPlayer.setDataSource(fd);
...
Khalyng
Freshman
Freshman
 
Posts: 3
Joined: Wed Jan 14, 2009 6:10 pm

Re: Media player prepare error

Postby onetx » Fri Mar 25, 2011 12:02 pm

¡¡¡¡Thanks!!!! ¡¡¡¡Thanks!!!! ¡¡¡¡Thanks!!!! :D :D :D
onetx
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Sep 30, 2010 8:48 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 13 guests