After some Googling it appears this is a common problem but I have yet to find an actual solution. I haven’t tested on an actual device, but the emulator is cutting off my sound clips at around 80% done. I am playing back .wav files.
Does anyone know a programmatic solution to these problems?
edit:
public void play(Context context){
if (soundPlayer != null){
soundPlayer.release();
}
int rId = 0;
switch(aIndex){
case 0: rId = R.raw.c0; break;
case 1: rId = R.raw.c1; break;
case 2: rId = R.raw.c2; break;
case 3: rId = R.raw.c3; break;
case 4: rId = R.raw.c4; break;
case 5: rId = R.raw.c5; break;
case 6: rId = R.raw.c6; break;
case 7: rId = R.raw.c7; break;
case 8: rId = R.raw.c8; break;
case 9: rId = R.raw.c9; break;
case 10: rId = R.raw.c10; break;
case 11: rId = R.raw.c11; break;
case 12: rId = R.raw.c12; break;
case 13: rId = R.raw.c13; break;
case 14: rId = R.raw.v14; break;
case 15: rId = R.raw.v15; break;
case 16: rId = R.raw.v16; break;
case 17: rId = R.raw.v17; break;
case 18: rId = R.raw.v18; break;
case 19: rId = R.raw.v19; break;
case 20: rId = R.raw.v20; break;
case 21: rId = R.raw.v21; break;
case 22: rId = R.raw.v22; break;
case 23: rId = R.raw.v23; break;
default: rId = R.raw.error; break;
}
soundPlayer = MediaPlayer.create(context, rId);
if (soundPlayer != null){
soundPlayer.start();
}
}
Well for starters, I would try to make sure
MediaPlayer.create()function is called prior to thestart(). If it’s a game, load the sounds when they start a new game (creating a new media player for each sound). The reason why is because thecreatefunction will effectively load the sound file there and then, ready for smooth playback when you callstart. If you load the file every time before running it, not only are you doing more work than you need to, but it may have undesired effects on the emulator. I’m not sure if you’ve noticed, but the emulator isn’t exact the quickest tool out the shed compared to virtually any actual physical device. As a result, what I think may be happening is the emulator is ‘playing’ the sound and thinks that it is complete before the sound actually plays, mainly due to the emulator’s slow speed.Try it out on an actual device and I think you won’t have any problems.