I am not much experienced so I copied code from somewhere; but Now I can get the state mediaplayer; All I want to do is to get the current state of mediaplayer and then show pause button when it's playing ; and play button when it's paused/buffering;
I am using shoutcast streaming in it; I want to show pause button or something loading status when it is being loaded initially (buffering); and when it is loaded and started playing the the pause button ; and when for some reason it starts buffering again it should show play button or Loading status on main activity
here is my code;
public class Myradio extends AsyncTask implements OnBufferingUpdateListener {
private static Context mContext;
// private static MyProgressDialog pdialog;
public static MediaPlayer mp = new MediaPlayer();
private MediaPlayer mpLoop = new MediaPlayer();
public Myradio(Context theContext) {
mContext = theContext;
mp.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
public void onBufferingUpdate(MediaPlayer arg0, int arg1) {
Log.v("Buffring Update", "");
// TODO Auto-generated method stub
}
});
}
public static void startRadio(String streamUrl) {
mp.reset();
mp.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.e(getClass().getName(), "Error in MediaPlayer: (" + what
+ ") with extra (" + extra + ")");
return false;
}
});
try {
mp.setDataSource(streamUrl);
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
} catch (IllegalStateException e) {
} catch (IOException e) {
}
}
public static void stopRadio() {
mp.stop();
}
public static void resumeRadio() {
// mp.();
// mp.setLooping(false);
// mpLoop.stop();
}
@Override
protected Object doInBackground(Object... params) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
// TODO Auto-generated method stub
Log.v("Buffring Update", "Buffring Update");
}
}
You can do this like (see here):
if(MediaPlayer.isPlaying()){
//show the pause button
}
else{
//show the play button
}
Check this tut too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With