1

My application plays ShoutCast Streaming and the target OS is 1.6 and above. I have applied some code from NPR application with some modification.

Here is the code

mediaPlayer = new MediaPlayer();
mediaPlayer.reset();
mediaPlayer.setDataSource(url);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
// Log.d(LOG_TAG, "Preparing: " + playUrl);
mediaPlayer.prepareAsync();
mediaPlayer.start();`

The code doesnot play anything on simulator or device(Testing in Samsung Galaxy with 2.1).


Here is the LogCat message.

About to play http://88.191.81.31:8206
12-08 14:16:42.229: WARN/MediaPlayer(5520): info/warning (1, 26)
12-08 14:16:42.239: ERROR/PlayerDriver(1870): Command PLAYER_INIT completed with an error or info PVMFFailure
12-08 14:16:42.239: ERROR/MediaPlayer(5520): error (1, -1)
12-08 14:16:42.239: WARN/PlayerDriver(1870): PVMFInfoErrorHandlingComplete
12-08 14:16:42.259: ERROR/MediaPlayer(5520): start called in state 0
12-08 14:16:42.259: ERROR/MediaPlayer(5520): error (-38, 0)
12-08 14:16:42.299: INFO/MediaPlayer(5520): Info (1,26)
12-08 14:16:42.299: ERROR/MediaPlayer(5520): Error (1,-1)
12-08 14:16:42.304: ERROR/MediaPlayer(5520): Error (-38,0)


Here is the question. 1. Can you tell me whats happening in device? 2. How to solve this error?.

Robert Massaioli
  • 13,379
  • 7
  • 57
  • 73
Prasham
  • 6,646
  • 8
  • 38
  • 55

1 Answers1

4

You are calling start() too soon. Javadocs of MediaPlayer explain it (look at the picture):

  1. Either you have to call prepare() before you call start(), or

  2. You call prepareAsync() and wait for OnPreparedListener.onPrepared() to be called, then (possibly inside this method) call start().

Updated:

Shoutcast streams are nativelly supported only on 2.2. For earlier versions you must create local proxy that changes the response protocol from ICY (shoutcast) to HTTP, which the mediaplayer will support. Take a look at this:

http://code.google.com/p/npr-android-app/source/browse/trunk/Npr/src/org/npr/android/news/StreamProxy.java

This has previously been discussed:

Listen to a shoutcast with Android

Community
  • 1
  • 1
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • I have tried this. Its not working Here is the Updated Code `mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setDataSource(url); mediaPlayer.prepareAsync(); mediaPlayer.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { Log.i("In", "Prepared Listener"); mediaPlayer.start(); } });` The LogCat Message is in next Comment. – Prasham Dec 08 '10 at 09:47
  • WARN/MediaPlayer(6592): info/warning (1, 26) 12-08 15:18:18.214: INFO/MediaPlayer(6592): Info (1,26) 12-08 15:18:18.219: ERROR/PlayerDriver(1870): Command PLAYER_INIT completed with an error or info PVMFFailure 12-08 15:18:18.219: ERROR/MediaPlayer(6592): error (1, -1) 12-08 15:18:18.219: ERROR/MediaPlayer(6592): Error (1,-1) 12-08 15:18:18.219: WARN/PlayerDriver(1870): PVMFInfoErrorHandlingComplete – Prasham Dec 08 '10 at 09:48
  • First: `prepareAsync()` needs to be called after `setOnPreparedListener(..)`. Second: your error is thrown during `setDataSource()`, right? – Peter Knego Dec 08 '10 at 10:33
  • I believe you problem lies in the fact that 1.6 does not natively support Shoutcast. I updated the answer. – Peter Knego Dec 08 '10 at 10:41