Note that there are some explanatory texts on larger screens.

plurals
  1. POPlaying audiofiles one by one?
    primarykey
    data
    text
    <p>I'm newbie in java. So the program should take the user entered text and if there is "a" it gonna play a-sound, if there is "b" it gonna play b-sound.And it must play this sounds one by one even if there are multiple "a" or "b". Here is my code:</p> <pre><code> public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button bStart = (Button) findViewById(R.id.bStart); final EditText etStart = (EditText) findViewById(R.id.etStart); final EditText etFinish = (EditText) findViewById(R.id.etFinish); final char[] arr = etStart.getText().toString().toCharArray(); final MediaPlayer as = MediaPlayer.create(R2d2Activity.this, R.raw.as); final MediaPlayer bs = MediaPlayer.create(R2d2Activity.this, R.raw.bs); final SoundPool sp; final int a; final int b; final int t; sp = new SoundPool(2, AudioManager.STREAM_MUSIC, 0); a = sp.load(this, R.raw.as, 1); b = sp.load(this, R.raw.bs, 1); final String value = etStart.getText().toString(); final Thread timer = new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(1300); // Do some stuff } catch (Exception e) { e.getLocalizedMessage(); } } }); bStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int n = 0; String value; String first; value = etStart.getText().toString(); // TODO Auto-generated method stub //actual code for (int i=0; i&lt;value.length(); i++){ first = etStart.getText().toString().substring(i, i+1); if(first.contentEquals("a")){ as.start(); as.setOnCompletionListener(new OnCompletionListener(){ public void onCompletion(MediaPlayer arg0) { //when finished } }); }else{ } if(first.contentEquals("b")){ bs.start(); }else{ } } } }); </code></pre> <p>The problem is that it starts playing audio files all at one time. I tried to add some OnCompletionListener, but I don't know what to do with it. Help me please.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload