I want to play an RTSP audio stream in Android media player. I was trying to directly bind to an RTSP link in media player. Sometimes it's playing fine, but now it didn't play and showed a media player error:
MediaPlayer(808): error (1, -2147483648).
Where is the problem?
Here is my some part of the code:
public class PlayRadio extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
setDataSource(rtspUrl);
Log.e("inside doinbackground....", path);
return null;
}
#Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
player.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
player.start();
Toast.makeText(getApplicationContext(), "starting..", Toast.LENGTH_LONG).show();
}
});
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
}
private void setDataSource(String path2) {
// TODO Auto-generated method stub
player=new MediaPlayer();
try {
Uri a =Uri.parse("rtsp://stream.rtm.swiftserve.com/live/rtm/rtm-ch010");
player.setDataSource(getApplicationContext(),a);
player.prepareAsync();
}
catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Log.e("tempPath", tempPath);
}
This error MediaPlayer(808): error (1, -2147483648) simply tells that your the video file you are playing is not supported by your device.
Generally RTSP links uses .sdp format which is currently not supported by Android devices.
Please check here Supported Media Formats
Related
how to stream a online radio without any buffering after the player is played. It should buffered for few sec for continue playing the radio,but it get stuck for few sec and playing.
my Aync task:
class Player extends AsyncTask {
private ProgressDialog progress;
#Override
protected Boolean doInBackground(String... params) {
// TODO Auto-generated method stub
Boolean prepared;
try {
mediaPlayer.setDataSource(params[0]);
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
intialStage = true;
playPause = false;
control.setBackgroundResource(R.drawable.play);
mediaPlayer.stop();
mediaPlayer.reset();
}
});
mediaPlayer.prepare();
prepared = true;
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
Log.d("IllegarArgument", e.getMessage());
prepared = false;
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
prepared = false;
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
prepared = false;
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
prepared = false;
e.printStackTrace();
}
return prepared;
}
#Override
protected void onPostExecute(Boolean result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (progress.isShowing()) {
progress.cancel();
}
Log.d("Prepared", "//" + result);
mediaPlayer.start();
media.stop();
intialStage = false;
}
public Player() {
progress = new ProgressDialog(MainActivity.this);
}
#Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
this.progress.setMessage("Buffering...");
media.start();
}
}
public void mute1(View v){
speaker.setVisibility(View.VISIBLE);
mute.setVisibility(View.INVISIBLE);
mediaPlayer.setVolume(0,0);
media.setVolume(0,0);
seekbar.setClickable(false);
seekbar.setFocusable(false);
seekbar.setEnabled(false);
}
public void speaker1(View v){
speaker.setVisibility(View.INVISIBLE);
mute.setVisibility(View.VISIBLE);
mediaPlayer.setVolume(1,1);
media.setVolume(1,1);
seekbar.setClickable(true);
seekbar.setFocusable(true);
seekbar.setEnabled(true);
}
how to get my player prepare for the online radio without any streaming after player is started.
Please Help me..
my source is:
if (playPause) {
control.setBackgroundResource(R.drawable.play);
mediaPlayer.stop();
new Player().cancel(true);
media.stop();
media.reset();
mediaPlayer.reset();
if (mediaPlayer.isPlaying())
mediaPlayer.stop();
mediaPlayer.reset();
media.stop();
playPause = false;
} else {
control.setBackgroundResource(R.drawable.pause);
if (intialStage) {
new Player()
.execute("http://streaming.shoutcast.com/MUKILFMRADIO");
} else {
if (!mediaPlayer.isPlaying())
mediaPlayer.start();
}
}
playPause = true;
}
};
I would suggest to use Exoplayer than media player.ExoPlayer is an application level media player for Android. It provides an alternative to Android’s MediaPlayer API for playing audio and video both locally and over the Internet. ExoPlayer supports features not currently supported by Android’s MediaPlayer API, including DASH and SmoothStreaming adaptive playbacks. Unlike the MediaPlayer API, ExoPlayer is easy to customize and extend, and can be updated through Play Store application updates. This links give you better idea about Exoplayer.
https://developer.android.com/guide/topics/media/exoplayer.html
https://github.com/google/ExoPlayer
I'm loading audio sounds into a listview, I play them.When the audio playing is done, i want to change that specific sound's pause button to play button again.
here is my code to play sounds
soundChild.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
player.setDataSource(url);
// file.close();
player.prepare();
player.setLooping(false);
// player.start();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (player.isPlaying()) {
if (player != null) {
player.pause();
// Changing button image to play button
soundChild.setImageResource(R.drawable.playbutton);
}
} else {
// Resume song
if (player != null) {
player.start();
// Changing button image to pause button
soundChild.setImageResource(R.drawable.pausebutton);
}
}
}
});
player.setOnCompletionListener(new OnCompletionListener() {
#Override public void onCompletion(MediaPlayer mp) { // TODO
// Auto-generated method stub player.release(); player=null;
Toast.makeText(_context, "complete", Toast.LENGTH_LONG).show();
soundChild.setImageResource(R.drawable.playbutton);
player.reset();
} });
But on complete listner the imageview of player button is never changed back to play imageview again. I doin't know where i'm doing wrong, because if onComplete is being called then imageview background should also change.please help.
Usually You have to call requestLayout before:
soundChild.requestLayout();
soundChild.setImageResource(R.drawable.playbutton);
and then after changing the image
soundChild.invalidate();
What else could You try? If it doesn´t work, You can also try:
soundChild.setImageDrawable(context.getResources().getDrawable(R.drawable.playbutton));
Because, like described in the API for setImageResource:
This does Bitmap reading and decoding on the UI thread, which can
cause a latency hiccup
Also, what it is possible, You have to call it in on ui thread:
runOnUiThread(new Runnable() {
#Override
public void run() {
soundChild.setImageResource(R.drawable.playbutton);
}
});
and call this in onCompletion.
Require develop streaming audio playback with mediaplayer on android.
Any ideas ?!
Thanks
I try the following code:
play.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String url = "http://stream.radiosai.net:8002/"; // your URL here
MP.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
MP.setDataSource(url);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MP.prepareAsync();
MP.start();
}
});
The above does not work Error deploying
MP.start();
Should be called after the mediaplager is ready, in setOnPreparedListener.
When you create MediaPlayer object, add prepared listener
MP.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
The German computer magazine C't recently published an article with the source code for an Android alarm clock radio. You can download the project files here. I think this contains everything that you need.
Want to do a audio streaming for a URL. The same URL is playing a live radio while running on the mobile browser. But while using MediaPlayer for android app there is no output. It gives the following error.
09-07 05:16:37.539: E/MediaPlayer(1265): error (1, -2147483648)
09-07 05:16:37.539: W/System.err(1265): java.io.IOException: Prepare failed.: status=0x1
My code sample is :
try {
Log.i("Audio Streaming", "start-->");
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(URL_OF_AUDIO);
mediaPlayer.prepare();
mediaPlayer.start();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
make sure that URL which is passing is valid and check the androidmanifest whether it is having the access permission.
use onprepared listener to start the video to avoid some unwanted exceptions.
try this one it works fine........
public class test extends Activity implements OnErrorListener, OnPreparedListener {
private MediaPlayer player;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
player.setDataSource("http://www.hubharp.com/web_sound/BachGavotte.mp3");
player.setOnErrorListener(this);
player.setOnPreparedListener(this);
player.prepareAsync();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
#Override
public void onDestroy() {
super.onDestroy();
player.release();
player = null;
}
#Override
public void onPrepared(MediaPlayer play) {
play.start();
}
#Override
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
return false;
}
}
I am streaming mp3 on media-player, it plays continuos when your screen is on or you are doing multitasking but when you turn off screen it won't play audio continuously, it stucks many times.And I got this "info/warning (702,0) "on log cat
I tried mp.setWakeMode(getBaseContext(),PowerManager.FULL_WAKE_LOCK);
I am using service to play audio streaming but still it stucks.
public class myPlayService extends Service{
MediaPlayer mp;
String link ="http://85.23.194.72:70/mp3/str";
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onCreate() {
mp = new MediaPlayer();
try {
mp.setDataSource(link);
mp.setWakeMode(getBaseContext(),PowerManager.FULL_WAKE_LOCK);
mp.prepareAsync();
mp.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.start();
}
});
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}#Override public void onDestroy() { mp.stop();mp.release();}}