我正在尝试制作手风琴虚拟乐器。 所以我想循环一个样本,直到我按下按钮并在按钮释放时停止。
使用MediaPlayer
时遇到很多问题:
1)我在最后一个版本上一直在使用.pause()
并且我得到了一些初步错误:在播放了一定数量的按钮之后,我推出的任何新按钮都没有声音,但我之前推过的按钮没有声音"静音"还在工作所以我期待这是.pause()
和内存使用的问题所以我使用.stop()
并在.prepareAsyc()
之后但我得到了新的错误:
- 一开始有些声音并且工作正常。 - 过了一会儿,每个按钮都没有声音。 - 再次尝试应用程序崩溃...
01-22 11:07:59.062: D/ActivityManager(55): Received spurious death notification for thread android.os.BinderProxy@43d797f0
01-22 11:07:59.182: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:07:59.442: W/AudioFlinger(30): write blocked for 107 msecs, 1 delayed writes, thread 0xb388
01-22 11:08:00.182: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:08:04.890: W/AudioFlinger(30): write blocked for 93 msecs, 9 delayed writes, thread 0xb388
01-22 11:08:06.042: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:08:07.042: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:08:07.702: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:08:08.412: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:08:46.616: W/AudioFlinger(30): write blocked for 72 msecs, 23 delayed writes, thread 0xb388
01-22 11:08:54.570: W/AudioFlinger(30): write blocked for 90 msecs, 42 delayed writes, thread 0xb388
01-22 11:09:00.463: W/AudioFlinger(30): write blocked for 85 msecs, 68 delayed writes, thread 0xb388
01-22 11:09:05.752: W/AudioFlinger(30): write blocked for 77 msecs, 93 delayed writes, thread 0xb388
01-22 11:09:47.431: W/AudioFlinger(30): write blocked for 105 msecs, 97 delayed writes, thread 0xb388
01-22 11:09:52.872: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:09:53.036: W/AudioFlinger(30): write blocked for 80 msecs, 114 delayed writes, thread 0xb388
01-22 11:09:53.532: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:09:57.282: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:09:58.066: W/AudioFlinger(30): write blocked for 73 msecs, 140 delayed writes, thread 0xb388
01-22 11:09:58.843: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:09:59.582: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:00.553: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:01.512: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:02.232: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:02.952: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:03.214: W/AudioFlinger(30): write blocked for 93 msecs, 157 delayed writes, thread 0xb388
01-22 11:10:03.802: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:04.992: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:06.062: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:07.352: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:07.902: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:08.282: W/AudioFlinger(30): write blocked for 93 msecs, 172 delayed writes, thread 0xb388
01-22 11:10:09.932: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:10.562: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:10.574: E/AudioFlinger(30): not enough memory for AudioTrack size=49216
01-22 11:10:10.574: D/MemoryDealer(30): AudioTrack (0x189460, size=1048576)
01-22 11:10:10.574: D/MemoryDealer(30): 0: 00189498 | 0x00000000 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 1: 00189570 | 0x0000C040 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 2: 0018cc90 | 0x00018080 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 3: 00189b28 | 0x000240C0 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 4: 001939c8 | 0x00030100 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 5: 00196c40 | 0x0003C140 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 6: 00199eb0 | 0x00048180 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 7: 0019a8b8 | 0x000541C0 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 8: 0019ad10 | 0x00060200 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 9: 001a15d0 | 0x0006C240 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 10: 001a1a18 | 0x00078280 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 11: 001a50a8 | 0x000842C0 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 12: 001aeb00 | 0x00090300 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 13: 001ab990 | 0x0009C340 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 14: 001b4fb8 | 0x000A8380 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 15: 001b8660 | 0x000B43C0 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 16: 001b54f0 | 0x000C0400 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 17: 001bef78 | 0x000CC440 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 18: 001c2608 | 0x000D8480 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 19: 001b8ba8 | 0x000E44C0 | 0x0000C040 | A
01-22 11:10:10.574: D/MemoryDealer(30): 20: 001c8ab0 | 0x000F0500 | 0x0000C040 | A
01-22 11:10:10.574: E/AudioTrack(30): AudioFlinger could not create track, status: -12
01-22 11:10:10.574: E/AudioSink(30): Unable to create audio track
01-22 11:10:10.574: E/VorbisPlayer(30): mAudioSink open failed
01-22 11:10:11.292: D/AudioSink(30): bufferCount (4) is too small and increased to 12
01-22 11:10:11.292: E/AudioFlinger(30): not enough memory for AudioTrack size=49216
01-22 11:10:11.304: D/MemoryDealer(30): AudioTrack (0x189460, size=1048576)
01-22 11:10:11.304: D/MemoryDealer(30): 0: 00189498 | 0x00000000 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 1: 00189570 | 0x0000C040 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 2: 0018cc90 | 0x00018080 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 3: 00189b28 | 0x000240C0 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 4: 001939c8 | 0x00030100 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 5: 00196c40 | 0x0003C140 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 6: 00199eb0 | 0x00048180 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 7: 0019a8b8 | 0x000541C0 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 8: 0019ad10 | 0x00060200 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 9: 001a15d0 | 0x0006C240 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 10: 001a1a18 | 0x00078280 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 11: 001a50a8 | 0x000842C0 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 12: 001aeb00 | 0x00090300 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 13: 001ab990 | 0x0009C340 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 14: 001b4fb8 | 0x000A8380 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 15: 001b8660 | 0x000B43C0 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 16: 001b54f0 | 0x000C0400 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 17: 001bef78 | 0x000CC440 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 18: 001c2608 | 0x000D8480 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 19: 001b8ba8 | 0x000E44C0 | 0x0000C040 | A
01-22 11:10:11.304: D/MemoryDealer(30): 20: 001c8ab0 | 0x000F0500 | 0x0000C040 | A
01-22 11:10:11.304: E/AudioTrack(30): AudioFlinger could not create track, status: -12
01-22 11:10:11.304: E/VorbisPlayer(30): mAudioSink open failed
这也是我活动的代码:
package com.soundbutton;
import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
public class Main extends Activity implements OnTouchListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final MediaPlayer sound01 = MediaPlayer.create(this, R.raw.sound1);
final MediaPlayer sound02 = MediaPlayer.create(this, R.raw.sound2);
final MediaPlayer sound03 = MediaPlayer.create(this, R.raw.sound3);
final MediaPlayer sound04 = MediaPlayer.create(this, R.raw.sound4);
///////////////////////////////////First line/////////////////////
final Button b11 = (Button) this.findViewById(R.id.sound1);
b11.setOnTouchListener(new OnTouchListener(){public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
sound01.setLooping(true);
sound01.start(); return true;
case MotionEvent.ACTION_UP:
sound01.stop();
sound01.prepareAsync();
return true; } return true; }});
final Button b12 = (Button) this.findViewById(R.id.sound2);
b12.setOnTouchListener(new OnTouchListener(){public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
sound02.setLooping(true);
sound02.start(); return true;
case MotionEvent.ACTION_UP:
sound02.stop();
sound02.prepareAsync();
return true; } return true; }});
final Button b13 = (Button) this.findViewById(R.id.sound3);
b13.setOnTouchListener(new OnTouchListener(){public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
sound03.setLooping(true);
sound03.start(); return true;
case MotionEvent.ACTION_UP:
sound03.stop();
sound03.prepareAsync();
return true; } return true; }});
final Button b14 = (Button) this.findViewById(R.id.sound4);
b14.setOnTouchListener(new OnTouchListener(){public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
sound04.setLooping(true);
sound04.start(); return true;
case MotionEvent.ACTION_UP:
sound04.stop();
sound04.prepareAsync(); return true; } return true; }});
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
}
}
希望你能帮助我;)
最佳Ewen的