I'm new to Android, and I'm trying to do something simple, like playing custom MP3s when a button is pressed. It looks like a question , but although my code follows the examples and I get no errors, I can not hear any sound either in the simulator or in the real phone.
My MainActivity.java:
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;
}
}
And my activity_main.xml:
<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" >
<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" />
<Button
android:id="@+id/play_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/play_button" />
</RelativeLayout>
I am developing using the Eclipse plugin, which does not show any errors and seems to run the application correctly in a simulator or on a real phone, but when I press the play button nothing happens. I'm not sure if the simulator supports sound (but I assume that it does), and I confirmed that the sound is muted on my phone.
What am I doing wrong?
, , , Eclipse, LogCat. , -?