Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Streaming Wav Audio Error: MediaPlayer Prepare failed: status=0x1

We are streaming audio via http from ffserver/ffmpeg on Angstrom Linux. The ffmpeg audio codec is PCM signed 16-bit little endian "pcm_s16le". The ffmpeg stream format is "wav". Both of these are claimed to be supported on Android here: http://developer.android.com/guide/appendix/media-formats.html#core

VLC finds and plays the stream without any problems. Under VLC "Codec Details", it says: Type: Audio, Codec: PCM S16 LE (araw) Channels: Stereo Sample rate: 48000 Hz Bits per sample: 16

We built the simple test application below to pick up and play the stream in Android and get this error: java.io.IOException: Prepare failed.: status=0x1

We checked the HTTP header using HTTP Debugger Pro. The Response Header items (when playing normally via VLC) are: [Response]: HTTP/1.0 200 OK Pragma: no-cache Content-Type: audio/x-wav

We have been searching the web for help on this issue for over two days and have come up empty-handed. Any help would be greatly appreciated.

------------TEST APP------------------------ package com.shaneahern.streamtest; import java.io.IOException; import android.app.Activity; import android.media.AudioManager; import android.media.MediaPlayer; import android.os.Bundle; import android.util.Log;

public class BareBonesStreamTestActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

    String streamUrl = "http://192.168.24.123:8080/test.wav"; 

    MediaPlayer mp = new MediaPlayer(); 
    Log.i("BareBonesStreamTestActivity", "MediaPlayer created"); 

    try { 
        mp.setDataSource(streamUrl); 
        Log.i("BareBonesStreamTestActivity", "setDataSource to " + streamUrl); 

        mp.setAudioStreamType(AudioManager.STREAM_MUSIC); 
        Log.i("BareBonesStreamTestActivity", "setAudioStreamType to AudioManager.STREAM_MUSIC"); 

        mp.prepare(); 
        Log.i("BareBonesStreamTestActivity", "prepare succeeded, calling start"); 

        mp.start(); 
    } catch (IllegalStateException e) { 
        Log.i("BareBonesStreamTestActivity", "prepare failed with IllegalStateException"); 
        e.printStackTrace(); 
    } catch (IOException e) { 
        Log.i("BareBonesStreamTestActivity", "prepare failed with IOException"); 
        e.printStackTrace(); 
    } 
} 

}

------------ERROR LOG------------------------

I/BareBonesStreamTestActivity(  727): MediaPlayer created 
I/StagefrightPlayer(   33): setDataSource('http://192.168.24.123:8080/ test.wav') 
I/BareBonesStreamTestActivity(  727): setDataSource to http://192.168.24.123:8080/test.wav 
I/BareBonesStreamTestActivity(  727): setAudioStreamType to AudioManager.STREAM_MUSIC 
E/MediaPlayer(  727): error (1, -2147483648) 
I/BareBonesStreamTestActivity(  727): prepare failed with IOException 
W/System.err(  727): java.io.IOException: Prepare failed.: status=0x1 
W/System.err(  727):     at android.media.MediaPlayer.prepare(Native Method) 
W/System.err(  727):     at com.shaneahern.streamtest.BareBonesStreamTestActivity.onCreate(BareBonesStr eamTestActivity.java: 30) 
W/System.err(  727):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: 1047) 
W/System.err(  727):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2627) 
W/System.err(  727):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2679) 
W/System.err(  727):     at android.app.ActivityThread.access $2300(ActivityThread.java:125) 
W/System.err(  727):     at android.app.ActivityThread $H.handleMessage(ActivityThread.java:2033) 
W/System.err(  727):     at android.os.Handler.dispatchMessage(Handler.java:99) 
W/System.err(  727):     at android.os.Looper.loop(Looper.java:123) 
W/System.err(  727):     at android.app.ActivityThread.main(ActivityThread.java:4627) 
W/System.err(  727):     at java.lang.reflect.Method.invokeNative(Native Method) 
W/System.err(  727):     at java.lang.reflect.Method.invoke(Method.java:521) 
W/System.err(  727):     at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:868) 
W/System.err(  727):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
W/System.err(  727):     at dalvik.system.NativeStart.main(Native Method) 
like image 270
nbonwit Avatar asked Jul 12 '11 22:07

nbonwit


2 Answers

I think you might want to take a look at: Using AudioTrack to play Wav file

Another usefull link

I have downloaded a raw stream myself and it works nicely.

like image 178
Ronnie Avatar answered Oct 18 '22 07:10

Ronnie


Though this is late, I also got the same error when was working with MediaPlayer.

After some R&D I found the source of the problem. For Future I write down it to answer area

In my case this occurred because I gave UnSupported File to MediaPlayer.

So, If this happens then check that your given file is right.

Other reasons:

  1. File path error, incorrect URI or directory
  2. Permission Problem
like image 1
Sayem Avatar answered Oct 18 '22 08:10

Sayem