gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 01:49:00 25 4
gpt4 key购买 nike

这是我的第一个Android / Java应用程序。我正在使用第一个答案here尝试启动重复任务,更新了搜索栏(“timeSlider”)以在播放音频文件时显示进度。这是我的代码(消除了一些不相关的行):

 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();
}

该项目不会显示在模拟器中。工具提示显示以下错误:

enter image description here

另外, startUpdateTimeSliderstopUpdateTimeSlider函数在工具提示中显示此错误:

enter image description here

另外,在“运行”窗口中,我得到:

emulator: emulator window was out of view and was recentered

emulator: ERROR: _factory_client_recv: Unknown camera factory query name in ' '



任何帮助将不胜感激!

最佳答案

第一个问题是自我解释,您需要添加final修饰符。

final Runnable doUpdateTimeSlider = ...

第二个-移动 startUpdateTimerSlider()方法,现在在 onCreate()方法内部

看起来您错过了 }:
@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();
}
};
}//<--------HERE

void startUpdateTimeSlider() {
doUpdateTimeSlider.run();
}

关于java - Android Java:更新seekbar以在播放音频文件时显示进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41413177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com