title: Playing a sound when button clicking in Android
body: <p>I'm new to Android, and I'm trying to do something simple like play a custom MP3 when a button is clicked. This seems to be a <a href="https://stackoverflow.com/questions/2618182/how-to-play-ringtone-alarm-sound-in-android">fairly</a> <a href="https://stackoverflow.com/questions/3663847/how-to-add-a-file-to-an-android-project-deploy-it-to-the-device-and-then-open">common</a> <a href="https://stackoverflow.com/questions/4861859/implement-sound-in-android-application">question</a>, but even though my code follows the examples, and I'm not getting any errors, I don't hear any sound in either the simulator or a real phone.</p>
  
  <p>My MainActivity.java:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      private static final String TAG = "MyActivity";
  
      public void MyActivity(Bundle onSavedStateInstance) {
          Log.v(TAG, "Initializing sounds...");
  
          final MediaPlayer mp = MediaPlayer.create(this, R.raw.alarma_67560);
  
          Button play_button = (Button)this.findViewById(R.id.play_button);
          play_button.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  Log.v(TAG, "Playing sound...");
                  mp.start();
              }
          });
          Log.v(TAG, "Sounds initialized.");
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  
  }
  </code></pre>
  
  <p>And my activity_main.xml:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_centerVertical="true"
          android:padding="@dimen/padding_medium"
          android:text="@string/hello_world"
          tools:context=".MainActivity" /&gt;
  
      &lt;Button
          android:id="@+id/play_button"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/play_button" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I'm developing using the Eclipse plugin, which doesn't show any errors and seems to run the app correctly in the simulator or real phone, but when I click the play button, nothing happens. I'm not sure if the simulator supports sound (but I'm assuming it does) and I've confirmed sound is unmuted on my phone.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Also, I'm not seeing my logging statements shown anywhere, either in Eclipse's console or the LogCat panel. Should I be seeing those printed somewhere?</p>