title: Play sound every 6-10 seconds
body: <p>How do you repeat a sound every 6-10 seconds, meaning a random interval between 6 and 10? So the sound plays 6, then 7, 6, 10, etc? So far I have this, which works how I want and plays the sound “once” and changes the button on the screen. However to play the sound again i must click the button to “stop” then click again to “go”. I want to Hit then button and have the sound repeat every 6-10 seconds until you hit the stop button...</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
  MediaPlayer myMediaPlayer = null;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      final MediaPlayer myMediaPlayer = MediaPlayer.create(this, R.raw.whistle);
      Timer soundTimer = new Timer();
  
      Random r = new Random();
  
  
      //Button related to play btn
      final Button startStopButton = (Button) findViewById(R.id.startstopbutton);
      startStopButton.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
  
              if (startStopButton.getText().equals("Start")) {
                  //start the sound
  
  
                  //change button color and text
                  startStopButton.setText("Stop");
                  startStopButton.setBackgroundColor(Color.RED);
  
                  myMediaPlayer.start();
  
  
  
              } else  {
                  //stop whistle
  
                  //change button color and text
                  startStopButton.setText("Start");
                  startStopButton.setBackgroundColor(Color.GREEN);
  
  
  
  
              }
  
  
          }
      });
  
  }
  </code></pre>