<ProgressBar android:id="@+id/progreso" 
        style="?android:attr/progressBarStyleHorizontal" 
import android.app.Activity; 
import android.media.MediaPlayer; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.ProgressBar; 
import android.widget.TextView; 
 
public class Player extends Activity implements Runnable, OnClickListener{ 
 
   private TextView Status; 
   private ProgressBar progressBar; 
   private Button StartMedia; 
   private Button Stop; 
   private MediaPlayer mp;       
 
   @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
 
       Status = (TextView) findViewById(R.id.Status); 
        progressBar = (ProgressBar) findViewById(R.id.progressBar); 
        StartMedia = (Button) findViewById(R.id.StartMedia); 
        Stop = (Button) findViewById(R.id.Stop); 
 
        StartMedia.setOnClickListener(this); 
        Stop.setOnClickListener(this);                 
    }         
 
@Override 
public void onClick(View v) { 
        if(v.equals(StartMedia)){ 
            if(mp != null && mp.isPlaying()) return; 
            mp = MediaPlayer.create(Player.this, R.raw.exodus_piranha); 
            mp.start();                
            Status.setText(R.string.PlayingMedia);          
            progressBar.setVisibility(ProgressBar.VISIBLE); 
            progressBar.setProgress(0); 
            progressBar.setMax(mp.getDuration()); 
            new Thread(this).start(); 
        } 
 
        if(v.equals(Stop) && mp!=null){ 
            mp.stop(); 
            mp = null;             
            Status.setText(R.string.Stopped); 
            progressBar.setVisibility(ProgressBar.GONE); 
        } 
 
} 
 
    @Override 
    public void run() { 
        int CurrentPosition= 0; 
        int total = mp.getDuration(); 
        while(mp!=null && CurrentPosition<total){ 
            try { 
                Thread.sleep(1000); 
                CurrentPosition= mp.getCurrentPosition(); 
            } catch (InterruptedException e) { 
                return; 
            } catch (Exception e){ 
                return; 
            }             
            progressBar.setProgress(CurrentPosition); 
        } 
    } 
 
 
}
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6