Android的AudioTrack慢速播放 [英] Android AudioTrack slow playback

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

问题描述

我想播放音乐使用AudioTrack。
轨道播放,但是音频播放以一半的速率。这就像这首歌已成为慢动作。

I'm trying to stream music in using AudioTrack. The track plays, but the audio plays at half the rate. It's like the song has become slow motion.

try{
    AudioTrack track= new AudioTrack( AudioManager.STREAM_MUSIC,
        44100,
        android.media.AudioFormat.CHANNEL_CONFIGURATION_MONO,
        android.media.AudioFormat.ENCODING_PCM_16BIT,

        android.media.AudioTrack.getMinBufferSize( 44100,
                android.media.AudioFormat.CHANNEL_CONFIGURATION_STEREO,
                android.media.AudioFormat.ENCODING_PCM_16BIT ),
        AudioTrack.MODE_STREAM );

System.out.println("Min buffer: " + android.media.AudioTrack.getMinBufferSize( 44100,
                android.media.AudioFormat.CHANNEL_CONFIGURATION_STEREO,
                android.media.AudioFormat.ENCODING_PCM_16BIT ));


  int cnt;
  int totalWrite = 0;
  boolean play = true;
  byte buff[]=new byte[16384];
  while((cnt=CircularByteBuffer.getInstance().getInputStream().read(buff))>0){

      totalWrite += cnt;
      System.out.println("Writing: " + cnt);
      track.write(buff, 0, cnt);

      if ( totalWrite > 60000 && play ){

          track.play();
          play = false;
      }
  }



      }catch (Exception e)
      {
}//end catch    

在CircularByteBuffer时,字节被写入另一个线程上和在这一个读取。这首歌一直起着没有任何停顿,但它只是起到以缓慢的速度。我不知道它可能是什么。任何想法?

In the CircularByteBuffer, the bytes are being written on another thread and read on this one. The song plays consistently without any pauses, but it just plays at a slow rate. I have no idea what it could be. Any ideas?

推荐答案

假设这是事实立体声流,你为什么要创建 AudioTrack CHANNEL_CONFIGURATION_MONO

Assuming this is in fact a stereo stream, why are you creating the AudioTrack with CHANNEL_CONFIGURATION_MONO?

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

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