1. Check out our companion app, Forums for Android! Download from Google Play

Making a sound repeat

Discussion in 'Application Development' started by cr5315, Aug 24, 2010.

  1. cr5315

    cr5315 Well-Known Member
    Thread Starter
    68

    Jul 23, 2010
    435
    158
    68
    Narnia
    I have an app that plays a sound when it is opened, but I would like it to repeat until the app is closed. I've gotten the sound to play once, but I can't figure out how to make it repeat.

    Code (Text):
    1. import android.app.Activity;
    2. import android.media.MediaPlayer;
    3. import android.os.Bundle;
    4.  
    5. public class ObeyActivity extends Activity {
    6.     /** Called when the activity is first created. */
    7.     @Override
    8.     public void onCreate(Bundle savedInstanceState) {
    9.         super.onCreate(savedInstanceState);
    10.         setContentView(R.layout.main);
    11.         final MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.laugh);
    12.         mp.start();
    13.     }
    14. }
     

    Advertisement

  2. DominicDroid

    DominicDroid New Member
    5

    Aug 24, 2010
    3
    0
    5
    Add the following line of code before you call mp.start(). The sound will repeat until pause or stop is called.

    Code (Text):
    1. mp.setLooping(true);
     

Share This Page

Loading...