When I use prepare(); on my mediaplayer, a black layout pops up till the mediaplayer is prepared.. I want to change that black screens layout, is that possible?
Asked
Active
Viewed 7,907 times
2 Answers
5
prepare();
is a blocking operation, if you dont want to block your UI Thread use prepareAsync();
.
Or use prepare in another Thread

Michele
- 6,126
- 2
- 41
- 45
4
Do all these thing in background thread until media player instance prepared the resource to play and show progress bar upto that time
//progressDialog
Thread th=new Thread(new Runnable() {
@Override
public void run() {
MediaPlayer md=new MediaPlayer();
try {
md.setDataSource("Path");
md.prepareAsync();
md.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//send message to handler
}
});
th.start();
//and then dissmiss dialog in handler class
Update
To know when media player will prepare
md.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
//Now your media player is ready to play
}
});

Tofeeq Ahmad
- 11,935
- 4
- 61
- 87
-
1Thannk alot. How can I see if the media player is prepared? – aamethk Sep 16 '11 at 13:19
-
3If you use another thread(that is other than UI thread) you dont need to use `prepareAsync()`. `mp.prepare()` is advisable at this scenario. – Fredrick Gauss Sep 24 '13 at 08:29