我想在Android应用程序中,在音频文件正在后台运行时更改图像,但遇到了问题。以下是我的代码:
public class SongActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_song);
final RelativeLayout rel = (RelativeLayout)findViewById(R.id.activity_song);
MediaPlayer mp = MediaPlayer.create(SongActivity.this,R.raw.thesong);
mp.start();
rel.setBackgroundResource(R.drawable.bday);
Runnable r = new Runnable() {
@Override
public void run() {
synchronized (this){
try {
wait(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
Thread test = new Thread(r);
test.start();
rel.setBackgroundResource(R.drawable.bday2);
}
}
请告知我是否可以修改它或者需要彻底重构。提前感谢您的帮助。