【发布时间】:2015-01-26 08:42:06
【问题描述】:
我的问题是我有大约 12 种声音和相同数量的图像。我想做的是用相应的图像播放声音,当声音结束时,用下一个图像播放下一个声音,依此类推,直到所有声音都播放完,我的意思是,一个接一个,而不是全部相同时间。
都是短音,所以我用的是 SoundPool。
有人可以帮帮我吗?提前谢谢你。
这是代码,抱歉,我忘了包含它...
String[] flauta = new String[]{"flauta_do","flauta_re","flauta_mi","flauta_fa","flauta_sol","flauta_la","flauta_si","flauta_do_agudo","flauta_re_agudo","flauta_mi_agudo","flauta_fa_agudo","flauta_sol_agudo"};
String[] pentagrama = new String[]{"pentagrama_do","pentagrama_re","pentagrama_mi","pentagrama_fa","pentagrama_sol","pentagrama_la","pentagrama_si","pentagrama_do_agudo","pentagrama_re_agudo","pentagrama_mi_agudo","pentagrama_fa_agudo","pentagrama_sol_agudo"};
String[] nota = new String[]{"Do","Re","Mi","Fa","Sol","La","Si","Do alto","Re alto","Mi alto","Fa alto","Sol alto"};
String[] sonido = new String[]{"sonido_do","sonido_re","sonido_mi","sonido_fa","sonido_sol","sonido_la","sonido_si","sonido_do_agudo","sonido_re_agudo","sonido_mi_agudo","sonido_fa_agudo","sonido_sol_agudo"};
private SoundPool sPool;
ImageView flautaIV;
ImageView pentagramaIV;
TextView notaTV;
int resID = 0;
String recurso = "";
int sonidoNota = 0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_repasar);
flautaIV = (ImageView)findViewById(R.id.flautaIV);
pentagramaIV = (ImageView)findViewById(R.id.pentagramaIV);
notaTV = (TextView)findViewById(R.id.notaTV);
sPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
for(int i = 0; i < flauta.length; i++)
{
recurso = flauta[i];
resID = getResources().getIdentifier(recurso, "drawable", getPackageName());
flautaIV.setImageResource(resID);
recurso = pentagrama[i];
resID = getResources().getIdentifier(recurso, "drawable", getPackageName());
pentagramaIV.setImageResource(resID);
notaTV.setText(nota[i]);
recurso = sonido[i];
resID = getResources().getIdentifier(recurso, "raw", getPackageName());
sonidoNota = sPool.load(this, resID, 1);
sPool.play(sonidoNota, (float)1.0, (float)1.0, 1, 0, 1f);
}
}
【问题讨论】:
-
请出示您的密码