我有一个媒体播放器,这是活动类中的搜索栏代码
public void updateProgressBar(){
mHandler.postDelayed(mUpdateTimeTask,100);
}
private Runnable mUpdateTimeTask = new Runnable(){
public void run(){
long totalDuration = mService.getDur();
long currentDuration = mService.getPosn();
// Displaying Total Duration time
start.setText(""+utils.milliSecondsToTimer(totalDuration));
// Displaying time completed playing
end.setText(""+utils.milliSecondsToTimer(currentDuration));
// Updating progress bar
int progress = (int)(utils.getProgressPercentage(currentDuration, totalDuration));
Log.d("Progress", ""+totalDuration);
seekBar.setProgress(progress);
// Running this thread after 100 milliseconds
mHandler.postDelayed(this, 100);
}
};
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// remove message Handler from updating progress bar
mHandler.removeCallbacks(mUpdateTimeTask);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
mHandler.removeCallbacks(mUpdateTimeTask);
int totalDuration = mService.getDur();
int currentPosition = utils.progressToTimer(mService.getPosn(), totalDuration);
// forward or backward to certain seconds
mService.seek(currentPosition);
// update timer progress again
updateProgressBar();
}
我在oncreate方法上调用了它
seekBar.setOnSeekBarChangeListener(this);
但是没有显示当前持续时间,当触摸搜索栏显示时,此错误显示:
致命的例外:主要
显示java.lang.NullPointerException
在com.music.Gramofone.Playmusic.onStopTrackingTouch
我不知道我的错误在哪里
编辑:这是我的处理程序
private Handler mHandler = new Handler();
这是我服务的一部分:
私人决赛IBinder mBinder = new LocalBinder();
/**
* Class used for the client Binder. Because we know this service always
* runs in the same process as its clients, we don't need to deal with IPC.
*/
public class LocalBinder extends Binder {
MusicService getService() {
// Return this instance of LocalService so clients can call public
// methods
return MusicService.this;
}
}
@Override
public IBinder onBind(Intent arg0) {
return mBinder;
}
public int getPosn(){
return mPlayer.getCurrentPosition();
}
public int getDur(){
return mPlayer.getDuration();
}
public boolean isPng(){
return mPlayer.isPlaying();
}
public void pausePlayer(){
mPlayer.pause();
}
public void seek(int posn){
mPlayer.seekTo(posn);
}
我也在活动中绑定服务