hi trying to put ProgressBar in MediaPlayer but not working i don't know what i m doing wrong
Please Help Me
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class ProgressBarPlay extends Activity {
private ProgressBar progressBar;
private Button Play;
private Button Stop;
MediaPlayer mPlayer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Play=(Button)findViewById(R.id.Play);
Stop=(Button)findViewById(R.id.Stop);
Play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(v.equals(Play)){
if(mPlayer != null && mPlayer.isPlaying()) return;
String url = "http://202.134.228.124:8002/";
try {
mPlayer = new MediaPlayer();
mPlayer.setDataSource(url);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.prepare();
mPlayer.start();
progressBar.setVisibility(ProgressBar.VISIBLE);
progressBar.setProgress(0);
progressBar.setMax(mPlayer.getDuration());
new Thread(this).start();
} catch (Exception e) {
Log.i("Exception", "Exception in streaming mediaplayer e = " + e);
}
}
Stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(v.equals(Stop) && mPlayer!=null){
}
try {
mPlayer.stop();
mPlayer = null;
progressBar.setVisibility(ProgressBar.GONE);
} catch (Exception e) {
Log.i("Exception", "Exception in streaming mediaplayer e = " + e);
}
}
@Override
public void run() {
int CurrentPosition= 0;
int total = mPlayer.getDuration();
while(mPlayer!=null && CurrentPosition<total){
try {
Thread.sleep(1000);
CurrentPosition= mPlayer.getCurrentPosition();
} catch (InterruptedException e) {
return;
} catch (Exception e){
return;
}
progressBar.setProgress(CurrentPosition);
}
}
}