2015-01-25 2 views
0

글쎄, 내 문제는 약 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); 

     } 

    } 
+0

코드를 표시하십시오 – joao2fast4u

답변

0

당신은 지정하지 않았다 그러나 나는 소리의 모든 거의 동시에 연주 겠지?

SoundPool.play은 차단되지 않으므로 즉시 루프를 감싸고 다음 사운드를로드하고 재생합니다. maxStreams 매개 변수에 대해 SoundPool1으로 초기화 했으므로 이전 스트림이 완료되기 전에 다음 스트림을로드하려고 할 때 어떤 동작을 얻으려고하는지 정확히 알 수 없습니다. 어쨌든 스트림이 완료 될 때까지 play 호출 후에 차단할 수 있어야합니다. SoundPool에는 본인이 알고있는 능력이 없습니다. 당신이 onCompletionListener을 정의 할 수있게 해주는 MediaPlayer을 사용할 필요가 있다고 생각합니다.

+0

답변 해 주셔서 감사합니다. MediaPlayer 및 해당 수신기로 코드를 변경하려면 어떻게해야합니까? – Mazinger

관련 문제