Android 2.2 Mediaplayer Is Working Fine with One Shoutcast Url But Not with the Other One

Android 2.2 MediaPlayer is working fine with one SHOUTcast URL but not with the other one

Shoutcast mp3 streaming from Android 2.2 onwards is supported natively .

Below 2.2 the Android OS cannot play shoutcast streams natively without using a proxy on the stream end or a stream proxy class on the device to capture the stream and pass it to the audioplayer just like NPR does.

audio/aacp streaming is not supported directly . For this you can use ffmpeg, opencore or faad2 library to decode it into PCM and play using audiotrack .Reference

Shoutcast stream work in 2.3 but not in 2.2

I inserted the direct link to the shoutcast directory. It seems that android 2.2 cant resolve the links.

eg: http://listen.technobase.fm/tunein-dsl-pls turned into http://85.17.26.115/

Android MediaPlayer works fine in Custom audio Streaming application up to Android 2.1 but not in higher versions

The StreamingMediaPlayer class is using a double-buffering technique to get around limitations in pre-1.2 releases of Android. All production releases of Android OS have included a MediaPlayer that supports streaming media(1). I would recommend doing that rather than using this double-buffering technique to get around the problem.

Android OS 2.2 replaced the old media player code with the FrightCast player which probably is acting differently in this case.

The line numbers in your stack trace don't map to the file you link to, so I assume there's a different version that you're actually using. I'm going to guess that that NullPointerException is being reported by MediaPlayer but neither the FileInputStream nor the returned FileDescriptor can be null.

(1) Prior to version 2.2 the media player wouldn't recognize ShoutCast streams with an "ICY/1.1" version header in the response. By creating a proxy that replaces this with "HTTP/1.1" you can resolve that. See the StreamProxy class here for an example.

Why won't this Java Android SHOUTcast MediaPlayer app code work?


MediaPlayer mp;
@Override
public void onCreate(){
mp = new MediaPlayer();
mp.setOnPreparedListener(this);
}
public void prepareplayer(){
mp.setDataSource(Url);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
Log.d(TAG, "Preparing..");
mp.prepareAsync();
}

@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
Log.d(TAG, "Prepared");
mp.play();
}

How to play shoutcast streaming in android 2.2

Try this code, detail is here:

import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class SimpleMusicStream extends Activity implements
MediaPlayer.OnCompletionListener, MediaPlayer.OnPreparedListener,
MediaPlayer.OnErrorListener, MediaPlayer.OnBufferingUpdateListener {

private String TAG = getClass().getSimpleName();
private MediaPlayer mp = null;

private Button play;
private Button pause;
private Button stop;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

play = (Button) findViewById(R.id.play);
pause = (Button) findViewById(R.id.pause);
stop = (Button) findViewById(R.id.stop);

play.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
play();
}
});

pause.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
pause();
}
});

stop.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
stop();
}
});
}

private void play() {
Uri myUri = Uri.parse("http://stream.radiosai.net:8002/");
try {
if (mp == null) {
this.mp = new MediaPlayer();
} else {
mp.stop();
mp.reset();
}
mp.setDataSource(this, myUri); // Go to Initialized state
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setOnPreparedListener(this);
mp.setOnBufferingUpdateListener(this);

mp.setOnErrorListener(this);
mp.prepareAsync();

Log.d(TAG, "LoadClip Done");
} catch (Throwable t) {
Log.d(TAG, t.toString());
}
}

@Override
public void onPrepared(MediaPlayer mp) {
Log.d(TAG, "Stream is prepared");
mp.start();
}

private void pause() {
mp.pause();
}

private void stop() {
mp.stop();

}

@Override
public void onDestroy() {
super.onDestroy();
stop();

}

public void onCompletion(MediaPlayer mp) {
stop();
}

public boolean onError(MediaPlayer mp, int what, int extra) {
StringBuilder sb = new StringBuilder();
sb.append("Media Player Error: ");
switch (what) {
case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
sb.append("Not Valid for Progressive Playback");
break;
case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
sb.append("Server Died");
break;
case MediaPlayer.MEDIA_ERROR_UNKNOWN:
sb.append("Unknown");
break;
default:
sb.append(" Non standard (");
sb.append(what);
sb.append(")");
}
sb.append(" (" + what + ") ");
sb.append(extra);
Log.e(TAG, sb.toString());
return true;
}

public void onBufferingUpdate(MediaPlayer mp, int percent) {
Log.d(TAG, "PlayerService onBufferingUpdate : " + percent + "%");
}

}

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:text="Play"
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button
android:text="Pause"
android:id="@+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button
android:text="Stop"
android:id="@+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>

MediaPlayer continue streaming after pause MP3

instead of using reset() method use pause()

android code for streaming shoutcast stream breaks in 2.2

I traced your error a little bit...
Looking down in Froyo's source code, in frameworks/base/media/libmedia/mediaplayer.cpp, it comes down to this function.
At this point, apparently the player argument is NULL

status_t MediaPlayer::setDataSource(const sp<IMediaPlayer>& player)
{
status_t err = UNKNOWN_ERROR;
sp<IMediaPlayer> p;
{ // scope for the lock
Mutex::Autolock _l(mLock);

if ( !( (mCurrentState & MEDIA_PLAYER_IDLE) ||
(mCurrentState == MEDIA_PLAYER_STATE_ERROR ) ) ) {
LOGE("setDataSource called in state %d", mCurrentState);
return INVALID_OPERATION;
}

clear_l();
p = mPlayer;
mPlayer = player;
if (player != 0) {
mCurrentState = MEDIA_PLAYER_INITIALIZED;
err = NO_ERROR;
} else {
LOGE("Unable to to create media player");
}
}

if (p != 0) {
p->disconnect();
}

return err;
}

That came from the function status_t MediaPlayer::setDataSource(const char *url, const KeyedVector<String8, String8> *headers) from the same file, where it was able to instantiate the IMediaPlayerService, but the create method must have failed for some reason...

One thing from the Android doc :
When done with the MediaPlayer, you should call release(), to free the resources. If not released, too many MediaPlayer instances may result in an exception.

Maybe you should check the createMediaPlayer function is called only once ? I guess that would have failed also with Eclair, but may be worth looking into...

Or maybe what you are looking at is what is described here

Hope that helps



Related Topics



Leave a reply



Submit