开发者

How to set seek bar value in Android?

开发者 https://www.devze.com 2023-01-23 12:34 出处:网络
Im developing one application which used SeekBar to control volume in MediaPlayer. The problem is when i move the seek bar at that time only the

Im developing one application which used SeekBar to control volume in MediaPlayer. The problem is when i move the seek bar at that time only the volume is increased, rest of the time default volume was set. Here is my code

seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
    public void onProgressChanged(SeekBar seekBar, int progress,
        boolean fromUser) 
    {
        //Log.i("Seek Bar"开发者_如何学Python, "" + validBpm);
        mp.setVolume(left, right);
    }
    public void onStartTrackingTouch(SeekBar seekBar)
    {
        left=left+20;
        right=right+20;
        mp.setVolume(left, right);
    }
    public void onStopTrackingTouch(SeekBar seekBar) {
        left=left-20;
        right=right-20;
        mp.setVolume(left, right);
    }
});


Looks like a simple fix although your original questions verbiage is really difficult to understand.

You're trying to use your own formula to set the volume and it doesn't look like those 2 methods are a good place to do it. Those two methods should only fire once, since they are only a startTouch or finishTouch.

You need to be using the "progress" integer provided from the onProgressChanged method to set the volume to the mediaplayer accordingly. This integer is the value of where the user set the seekBar.

0

精彩评论

暂无评论...
验证码 换一张
取 消