音频流在5秒后停止

时间:2012-10-18 03:37:21

标签: android android-audiomanager

我在onCreate()方法中执行以下操作:

mSound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
AudioManager mAudioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
soundID = mSound.load(this, R.raw.sample, 1);
streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
setVolumeControlStream(AudioManager.STREAM_MUSIC);

然后我想通过按下按钮播放声音文件......所以在我的onClick()方法中我有:

mSound.play(soundID, streamVolume, streamVolume, 1, 0, 1f);

效果很好......但仅仅5秒钟它就会切断......任何想法?谢谢。我正在测试DROID 3,如果有帮助的话。

2 个答案:

答案 0 :(得分:2)

为简短的音频文件创建SoundPool,例如通知文件...要播放长音频文件,只需使用 - ...

       private MediaPlayer mp_file;  

          ...........
       mp_file = MediaPlayer.create(getApplicationContext(), R.raw.big); 
       mp_file.start();

答案 1 :(得分:0)

你确认R.raw.sample实际上超过了5秒吗?

如果是这样,多少钱?因为注意SoundPool适用于短长度样本。如果您无法使SoundPool工作,请尝试使用MediaPlayer。它使用起来更简单,设计用于更长的样品。