I have a button when I clicked in it shows me an slide with a picture and plays an audio from my sd card with this code:
public void buttonClickHandler(View v) {
this.onClickNextDiapositiva();
Diapositiva diapo1 = this.getDiapoActual();
try {
if (diapo1.tieneSonido()) {
String sndPath = ZIP_SND_PATH + diapo1.getSonido().getNombre();
InputStream isSonido = this.getTutorFile().getFile(sndPath);
this.audioPlayer = new StreamingMediaPlayer(this);
this.audioPlayer.startStreaming(isSonido);
} else if (diapo1.tieneVideo()) {
if (!diapo1.tieneImagen()) {
String imgPath = ZIP_FONDOS_PATH开发者_StackOverflow中文版 + "fondo_video.png";
cargarImagen(imgPath);
}
}
} catch (Throwable ex) {
Log.e("mostrarDiapositiva", ex.getMessage());
Toast
.makeText(this, "Error: " + ex.getMessage(), Toast.LENGTH_SHORT)
.show();
}
break;
}
the fact is that the code works, the slide is changed and de audio played but it starts and when less than one second is played it started again, it´s like if it was stuttered.
Any idea why is this happening? thanks too much
Use MediaPlayer instead of StreamingMediaPlayer
for example:
MediaPlayer mp = new MediaPlayer();
// when you want to play the sound stored in nodeaudio:
// nodeaudio is a path like /min/sdcard/soundfile
if (nodeaudio == null || nodeaudio.trim().equals("")) {
mp.reset();
} else {
try {
mp.reset();
mp.setDataSource(nodeaudio);
mp.prepare();
mp.start();
}
catch(Exception e) {
Log.e("Play sound ERROR", e.toString());
e.printStackTrace();
}
}
精彩评论