Android заикался Аудио
У меня есть кнопка, когда я нажимаю на нее, показывает мне слайд с изображением и воспроизводит звук с моей SD-карты с этим кодом:
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 + "fondo_video.png";
cargarImagen(imgPath);
}
}
} catch (Throwable ex) {
Log.e("mostrarDiapositiva", ex.getMessage());
Toast
.makeText(this, "Error: " + ex.getMessage(), Toast.LENGTH_SHORT)
.show();
}
break;
}
Дело в том, что код работает, слайд изменяется и воспроизводится звук, но он запускается, и когда проигрывается менее одной секунды, он запускается снова, как если бы он заикался.
Есть идеи, почему это происходит? большое спасибо
1 ответ
Решение
Используйте MediaPlayer вместо StreamingMediaPlayer
например:
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();
}
}