java seekbar,Android Java:更新seekbar以在播放音频文件时显示进度

This is my first Android/Java app. I am using the first answer here to try to initiate a repeating task, updating a seekbar ("timeSlider") to show progress as an audio file plays. Here is my code (eliminating a few irrelevant lines):

private int timeSliderInterval = 1000; // 1 second

private Handler timeSliderHandler;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_play);

Intent intent = getIntent();

Runnable doUpdateTimeSlider = new Runnable() {

@Override

public void run() {

timeSliderHandler.postDelayed(doUpdateTimeSlider, timeSliderInterval);

updateTimeSlider();

}

};

void startUpdateTimeSlider() {

doUpdateTimeSlider.run();

}

void stopUpdateTimeSlider() {

timeSliderHandler.removeCallbacks(doUpdateTimeSlider);

}

final SeekBar timeSlider = (SeekBar) findViewById(R.id.timeSlider);

if (timeSlider != null) {

timeSliderHandler = new Handler();

startUpdateTimeSlider();

}

@Override

public void onDestroy() {

super.onDestroy();

stopUpdateTimeSlider();

}

The project does not display in the emulator. Tooltips show these errors:

3yKdx.png

In addition, the startUpdateTimeSlider and stopUpdateTimeSlider functions are showing this error in tooltips:

Ta6sc.png

Also, in the Run window, I'm getting:

emulator: emulator window was out of view and was recentered

emulator: ERROR: _factory_client_recv: Unknown camera factory query

name in ' '

Any help will be greatly appreciated!

解决方案

First issue is self explained, you need to add final modifier.

final Runnable doUpdateTimeSlider = ...

Second one - move startUpdateTimerSlider() method, now its inside onCreate() method

Looks like you missed }:

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_play);

Intent intent = getIntent();

Runnable doUpdateTimeSlider = new Runnable() {

@Override

public void run() {

timeSliderHandler.postDelayed(doUpdateTimeSlider, timeSliderInterval);

updateTimeSlider();

}

};

}//

void startUpdateTimeSlider() {

doUpdateTimeSlider.run();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值