[英]Android Java: Update seekbar to show progress as audio file plays
This is my first Android/Java app. 这是我的第一个Android / Java应用程序。 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. 我在这里使用第一个答案来尝试启动重复任务,更新搜索栏(“ timeSlider”)以在播放音频文件时显示进度。 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: 工具提示显示以下错误:
In addition, the startUpdateTimeSlider
and stopUpdateTimeSlider
functions are showing this error in tooltips: 另外, startUpdateTimeSlider
和stopUpdateTimeSlider
函数在工具提示中显示此错误:
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 ' ' 模拟器:错误:_factory_client_recv:“”中未知的相机工厂查询名称
Any help will be greatly appreciated! 任何帮助将不胜感激!
First issue is self explained, you need to add final
modifier. 第一个问题是自我解释,您需要添加final
修饰符。
final Runnable doUpdateTimeSlider = ...
Second one - move startUpdateTimerSlider()
method, now its inside onCreate()
method 第二个-移动startUpdateTimerSlider()
方法,现在将其放在onCreate()
方法中
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();
}
};
}//<--------HERE
void startUpdateTimeSlider() {
doUpdateTimeSlider.run();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.