我已經做了像用戶點擊按鈕然後聲音播放。但是現在我無法在點擊後聽到聲音。我不知道爲什麼?Android:爲什麼我點擊後無法播放按鈕上的聲音?
這是我用來播放聲音的代碼。
代碼:
case R.id.lockView:
playSound(R.raw.dooropen);
break;
}
public void playSound(int resources){
boolean mStartPlaying = true;
if (mStartPlaying==true){
mPlayer = new MediaPlayer();
Uri uri = Uri.parse("android.resource://com.project.iMystick/" + resources);
try{
mPlayer.setDataSource(getApplicationContext(),uri);
mPlayer.prepare();
mPlayer.start();
}
catch (IOException e){
Log.e(LOG_TAG, "prepare() failed");
}
}
else{
// stopPlaying();
//rePlay.setText("Replay");
mPlayer.release();
mPlayer = null;
}
mStartPlaying = !mStartPlaying;
}
而且一些點擊後,我得到了在logcat的這種類型的錯誤消息:
登錄:
03-27 16:15:02.737: ERROR/MediaPlayer(1057): Error (-19,0)
03-27 16:15:03.858: DEBUG/AudioSink(34): bufferCount (4) is too small and increased to 12
03-27 16:15:03.858: ERROR/AudioFlinger(34): not enough memory for AudioTrack size=32832
03-27 16:15:03.858: DEBUG/MemoryDealer(34): AudioTrack (0x12abf8, size=1048576)
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 0: 0012ac10 | 0x00000000 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 1: 0012aca0 | 0x00008040 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 2: 0012b5a8 | 0x00010080 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 3: 0012bec8 | 0x000180C0 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 4: 0012c7f0 | 0x00020100 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 5: 0012d1f0 | 0x00028140 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 6: 0012db20 | 0x00030180 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 7: 00136448 | 0x000381C0 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 8: 0013ee00 | 0x00040200 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 9: 0000de10 | 0x00048240 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 10: 0012b708 | 0x00050280 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 11: 00022c70 | 0x000582C0 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 12: 000234c0 | 0x00060300 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 13: 00115e38 | 0x00068340 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 14: 00117a80 | 0x00070380 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 15: 00118798 | 0x000783C0 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 16: 00042228 | 0x00080400 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 17: 0004bd48 | 0x00088440 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 18: 00055998 | 0x00090480 | 0x00008040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 19: 0005f5f0 | 0x000984C0 | 0x00003040 | A
03-27 16:15:03.858: DEBUG/MemoryDealer(34): 20: 000712b0 | 0x0009B500 | 0x00008040 | A
03-27 16:15:03.867: ERROR/AudioTrack(34): AudioFlinger could not create track, status: -12
03-27 16:15:03.867: ERROR/AudioSink(34): Unable to create audio track
03-27 16:15:03.877: ERROR/MediaPlayer(1057): error (-19, 0)
enter code here
是的謝謝。它解決了我的問題 – 2012-03-27 12:00:21