android 退出程序 seekbar mediaplayer
退出程序
android.os.Process.killProcess(android.os.Process.myPid());
seekbar空间:
<SeekBar
android:id="@+id/myseekbar"
android:layout_width="fill_parent"
android:layout_height="17dp"
android:layout_below="@id/music_playering_names"
android:layout_marginTop="115dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
/>
class seekbar_music extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
while(true){
setseekbar();
// myseekbar.postDelayed(null, 1000);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void setseekbar(){
if((str!=null)&&(MyService.mediaplayer.isPlaying())){
int pos = MyService.mediaplayer.getCurrentPosition(); //获得目前位置
int progressMax = myseekbar.getMax();
int playermax=MyService.mediaplayer.getDuration(); //获取总位置
myseekbar.setProgress(pos * progressMax / playermax); //设置进度条
}
}
}
myseekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
MyService.mediaplayer.seekTo(seekBar.getProgress() * MyService.mediaplayer.getDuration() / myseekbar.getMax());
MyService.mediaplayer.start();
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
MyService.mediaplayer.pause();
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
// MyService.mediaplayer.seekTo(progress * MyService.mediaplayer.getDuration() / myseekbar.getMax()); //如果这样会有延迟
}
});