我正在做soundpool应用程序,我能够成功编译应用程序,但是我收到了一些错误。我在.ogg格式的原始文件夹中有16个声音。我不知道soundpool资源的限制。应用程序有时加载声音但在扬声器中长时间停止。
以下是错误代码:
bad volume value, error creating AudioTrack, AudioFlinger could not create track status: -12
这是我的代码:
private SoundPool spool;
private SoundPool spool2;
private SoundPool spool3;
private SoundPool spool4;
private SoundPool spool5;
private SoundPool spool6;
private SoundPool spool7;
private SoundPool spool8;
private SoundPool spool9;
private SoundPool spool10;
private SoundPool spool11;
private SoundPool spool12;
private SoundPool spool13;
private SoundPool spool14;
private SoundPool spool15;
private SoundPool spool16;
private int soundID;
private int soundID2;
private int soundID3;
private int soundID4;
private int soundID5;
private int soundID6;
private int soundID7;
private int soundID8;
private int soundID9;
private int soundID10;
private int soundID11;
private int soundID12;
private int soundID13;
private int soundID14;
private int soundID15;
private int soundID16;
;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.talempong);
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID = spool.load(this, R.raw.doo, 1);
ImageButton Button = (ImageButton)findViewById(R.id.imagebutton1);
Button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool2 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID2 = spool2.load(this, R.raw.re, 1);
ImageButton Button2 = (ImageButton)findViewById(R.id.imagebutton2);
Button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound2();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool3 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID3 = spool3.load(this, R.raw.mi, 1);
ImageButton Button3 = (ImageButton)findViewById(R.id.imagebutton3);
Button3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound3();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool4 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID4 = spool4.load(this, R.raw.fa, 1);
ImageButton Button4 = (ImageButton)findViewById(R.id.imagebutton4);
Button4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound4();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool5 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID5 = spool5.load(this, R.raw.sol, 1);
ImageButton Button5 = (ImageButton)findViewById(R.id.imagebutton5);
Button5.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound5();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool6 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID6 = spool6.load(this, R.raw.la, 1);
ImageButton Button6 = (ImageButton)findViewById(R.id.imagebutton6);
Button6.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound6();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool7 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID7 = spool7.load(this, R.raw.si, 1);
ImageButton Button7 = (ImageButton)findViewById(R.id.imagebutton7);
Button7.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound7();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool8 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID8 = spool8.load(this, R.raw.do_tinggi, 1);
ImageButton Button8 = (ImageButton)findViewById(R.id.imagebutton8);
Button8.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound8();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool9 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID9 = spool9.load(this, R.raw.sol_rendah, 1);
ImageButton Button9 = (ImageButton)findViewById(R.id.imagebutton9);
Button9.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound9();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool10 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID10 = spool10.load(this, R.raw.la_rendah, 1);
ImageButton Button10 = (ImageButton)findViewById(R.id.imagebutton10);
Button10.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound10();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool11 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID11 = spool11.load(this, R.raw.si_rendah, 1);
ImageButton Button11 = (ImageButton)findViewById(R.id.imagebutton11);
Button11.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound11();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool12 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID12 = spool12.load(this, R.raw.re_kres, 1);
ImageButton Button12 = (ImageButton)findViewById(R.id.imagebutton12);
Button12.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound12();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool13 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID13 = spool13.load(this, R.raw.fa_kres, 1);
ImageButton Button13 = (ImageButton)findViewById(R.id.imagebutton13);
Button13.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound13();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool14 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID14 = spool14.load(this, R.raw.sol_kres, 1);
ImageButton Button14 = (ImageButton)findViewById(R.id.imagebutton14);
Button14.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound14();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool15 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID15 = spool15.load(this, R.raw.la_kres, 1);
ImageButton Button15 = (ImageButton)findViewById(R.id.imagebutton15);
Button15.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound15();
}
});
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
spool16 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundID16 = spool16.load(this, R.raw.re_tinggi, 1);
ImageButton Button16 = (ImageButton)findViewById(R.id.imagebutton16);
Button16.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Sound16();
//Pemanggil audio Talempong
}
});
}
public void Sound(){
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
float volume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
spool.play(soundID, volume, volume, 1, 0, 1f);