【发布时间】:2013-10-01 17:44:26
【问题描述】:
当我尝试此代码时,我的应用程序崩溃了? 我希望我不断检查 MediaPlayer (MP) 是否正在播放,如果是,我希望文本显示“正在播放”-但如果它没有播放,我希望它阅读“未播放”。
我没有收到来自 Eclipse 的任何警告,但是当我导出它时,它仍然在加载时崩溃。 我知道设置 TextView 的代码不存在,但这不是问题。 ( 我想 ) 如果有其他方法可以做到这一点,我会很高兴朝着正确的方向前进。
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//The Timer
Thread playingtimer = new Thread (){
public void run() {
try{
int time = 1;
while(time > 0) {
sleep(100);
if (MP.isPlaying()){
//set the TextView here "Now Playing"
}
else
//set the TextView to "NOT Playing"
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
finally{
}
}
};
playingtimer.start();
【问题讨论】:
-
发布 Logcat。没有它,很难诊断出崩溃。
标签: android multithreading timer oncreate