You cannot change the user interface from a background thread. MediaPlayer also provides an OnCompletionListener interface that you should probably use instead of a while loop. Infact, if you use onCompletionListener, you donโt even have to put this in your own stream, so you donโt have to worry about how to change the user interface.
something like this should work fine:
mp.setOnCompletionListner(new OnCompletionListner() { public void onCompletion(MediaPlayer m){ im.setImageResource(R.drawable.primeiro_misterio_gozoso07); } });
source share