1. Are you ready for the Galaxy S20? Here is everything we know so far!

Media Player doesn't play the sound simultaneously in android

Discussion in 'Android Development' started by Sathiyadevi, Feb 26, 2016.

  1. Sathiyadevi

    Sathiyadevi Lurker
    Thread Starter

    package in.research.hash_table;

    import android.media.AudioManager;
    import android.media.MediaPlayer;
    import android.media.SoundPool;
    import android.os.Bundle;

    import android.support.v7.app.AppCompatActivity;
    import android.widget.TextView;

    I read the character one by one from the string when switch the character a media player will play the a sound when switch the b character b sound will play simultaneously in android. can any one help me thanks in advance.

    here is my code...


    public class MainActivity extends AppCompatActivity {


    private static final String str="amio";

    TextView tv1,tv2;

    int count=0;
    SoundPool soundPool;
    int soundId;

    MediaPlayer mp;


    @override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    soundPool=new SoundPool(1, AudioManager.STREAM_MUSIC,1);
    soundId=soundPool.load(this,R.raw.thu,1);
    soundPool.play(soundId, 1, 1, 1, 1, 1f);


    tv1=(TextView)findViewById(R.id.tv1);
    tv2=(TextView)findViewById(R.id.tv2);
    tv1.append(str);
    for(int i=0;i<str.length();i++){
    if(Character.toString(str.charAt(i)).matches("[ameiou]")){
    switch(Character.toString(str.charAt(i))){

    case "a":
    tv2.append("a");
    mp=MediaPlayer.create(this,R.raw.a);

    break;
    case "m":
    tv2.append("m");
    mp=MediaPlayer.create(this,R.raw.m);

    break;
    case "i":
    tv2.append("i");
    mp=MediaPlayer.create(this,R.raw.i);

    break;
    case "o":
    tv2.append("o");
    mp=MediaPlayer.create(this,R.raw.o);


    break;
    case "u":
    tv2.append("u");

    break;
    }





    }

    mp.start();
    count++;



    }













    }




    }
     


Loading...
Similar Threads - Media Player doesn't
  1. P Garza
    Replies:
    0
    Views:
    321
  2. thetalk
    Replies:
    1
    Views:
    290
  3. Biffos
    Replies:
    8
    Views:
    604
  4. gnystrom
    Replies:
    8
    Views:
    441
  5. Android News
    Replies:
    0
    Views:
    638
  6. Peter22
    Replies:
    2
    Views:
    452
  7. Doctor Wizard
    Replies:
    1
    Views:
    446
  8. marinus4325
    Replies:
    4
    Views:
    713
  9. David Doyle
    Replies:
    4
    Views:
    1,331
  10. Monica Pinnedyr Jansen
    Replies:
    3
    Views:
    473

Share This Page

Loading...