title: Android mediaPlayer only plays file once
body: <p>I'm trying to create an app that play a certain audio file, that was previously recorded, when I press a button or shake my phone. Here is my code.</p>
  
  <pre><code>public class Reproduzir extends Activity implements SensorEventListener{
  MediaPlayer player = new MediaPlayer();
  SensorManager sensor;
  
  @Override
  protected void onCreate(Bundle savedInstanceState ){
      super.onCreate(savedInstanceState);
  
      sensor= (SensorManager) getSystemService(SENSOR_SERVICE);
      setContentView(R.layout.reproduzir);
      Button reproduzir = (Button) findViewById(R.id.reproduzir);
      reproduzir.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              play();
  
          }
      });
      Button fechar= (Button) findViewById(R.id.fechar);
      fechar.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              if (player.isPlaying()) {
                  player.stop();
                  player.release();
              }
              finish();
  
  
          }
      });
  
  }
  public void play(){
      try {
          player.setDataSource(Environment.getExternalStorageDirectory().getPath()+"/2cp.3gp");
          player.prepare();
          player.start();
      } catch (IllegalArgumentException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (SecurityException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IllegalStateException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  
  }
  public void onStart(){
      super.onStart();
      sensor.registerListener(this,sensor.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
              SensorManager.SENSOR_DELAY_FASTEST);
  }
  
  
  @Override
  public void onAccuracyChanged(Sensor sensor, int accuracy) {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void onSensorChanged(SensorEvent event) {
      // TODO Auto-generated method stub
      if(event.values[0]&gt;10.2
              ||event.values[1]&gt;10.2
              ||event.values[2]&gt;10.2){
          play();
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My problem is that when I run it, I can only play it once. If I press the button a second time or shake it again, it does nothing. Can anyone help?</p>