Scenario
I have a problem that starts to drive me nuts. In one activity I have the following scenario. On create:
– create a GPS Listner
– create a Location Listener
– Start GPS listner and location listener
– Start a asyncTask that downloads a map from the web / or load it from cache
– play a wav file which is a raw resource, very small (around 63 Kilo) which is short, basically it says: “Let’s head to the start point” and it makes visible a textview for 10 seconds.
Problem
Rarely the sound gets play fully. Sometimes I hear only “Let’s head”, sometimes “Let’s head to the star”, sometimes no play at all. It’s like something else is blocking the sound. I moved the sound in its own thread but still no success:
Code
private void ShowTextPlayVoice(String message, int soundResId)
{
txtProceed.setText(message);
txtProceed.setVisibility(View.VISIBLE);
final int soundId = soundResId;
Handler splashHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
txtProceed.setVisibility(View.INVISIBLE);
break;
}
super.handleMessage(msg);
}
};
Message msg = new Message();
msg.what = 0;
splashHandler.sendMessageDelayed(msg, 10000);
Thread thread = new Thread() {
public void run() {
MediaPlayer mp = MediaPlayer.create(ctx, soundId);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
}
};
thread.start();
}
Thank you all for help.
After some tries, here is a working solution