I have a Video Player using library and On him ImageView
, ie the type of banner that covers 30% of the video player. Every 15 seconds, the picture should change.
mBannerView.setImageBitmap (BitmapFactory.decodeFile (file.getAbsolutePath ()));
Thread.sleep (1000 * 15);
But I have a crash when changing the picture with the message:
Android "Only the original thread that created a view hierarchy can Touch its views. "
I tried to write these lines to UI
stream:
runOnUiThread (new Runnable () {
@Override
public void run () {
............
}
});
ImageView
but then does not respond to any timer or change.
I think right now (maybe wrong, in this case, please correct) that the focus is on the video player as the video plays, and so the picture above it is changed, crashes down.
If so, how in that case,
how not to lose focus with ImageView
while and continued to play a video?
And if not, what could be wrong?
UPD: code:
public void bannerSlide(boolean run) {
Timer timer = new Timer();
File file;
if (run){
mBannerView.setVisibility(View.VISIBLE);
final List<Banner> bannerList = GlobalData.loadBannerInfo(MainActivity.this);
if (bannerList != null && bannerList.size() > 0){
for (int i = 0; i < bannerList.size(); i++){
file = new File(Application.banner_path + bannerList.get(i).getName());
if (file.exists()){
mBannerView.setImageBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()));
}
final int finalI = i;
timer.schedule(new TimerTask() {
@Override
public void run() {
if (finalI == bannerList.size() - 1){
bannerSlide(true);
}
}
}, 15 * 1000);
}
} else {
mBannerView.setVisibility(View.GONE);
}
} else {
mBannerView.setVisibility(View.GONE);
timer.cancel();
}
}