媒体播放器寻求服务吧

时间:2014-08-25 09:55:28

标签: android service seekbar

我有一个媒体播放器和  这是活动类

中的搜索栏代码
   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);

但不显示当前持续时间,触摸搜索栏显示此错误:

 FATAL EXCEPTION: main
java.lang.NullPointerException
        at 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);
}

我也在活动中绑定服务

0 个答案:

没有答案