Android的音频结巴 [英] Android stuttered Audio

查看:170
本文介绍了Android的音频结巴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,当我点击它表明我的照片幻灯片的从我的SD卡播放音频与此code:

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 + "fondo_video.png";
           cargarImagen(imgPath);
           }
        }
    } catch (Throwable ex) {
       Log.e("mostrarDiapositiva", ex.getMessage());
       Toast
       .makeText(this, "Error: " + ex.getMessage(), Toast.LENGTH_SHORT)
       .show();
    }
    break;

}

的事实是,code ++工程,滑动被改变和去音频播放,但在启动时不到一秒播放它再次启动,汇入作业一样,如果它是口吃

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

推荐答案

使用的MediaPlayer,而不是StreamingMediaPlayer

Use MediaPlayer instead of 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();                 
    }             
}

这篇关于Android的音频结巴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆