The following program to play an MP3 loads, but stops in emulator. Not even UI displayed.
No error is indicated in Eclipse. If I run it without the button, it plays.
Do you have any idea what is wrong, and how to fix it?
************************
package com.example.mp3_trial;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity
{
private Button mPlay;
final MediaPlayer medp = MediaPlayer.create(this, R.raw.badbill);
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.activity_main);
mPlay = (Button) findViewById(R.id.play);
/** If I put this here instead of above, Eclipse says medp is not used.
MediaPlayer medp = MediaPlayer.create(this, R.raw.badbill);
*/
mPlay.setOnClickListener(new OnClickListener()
{
public void onClick(View view)
{
medp.start();
}
});
} //bundle
} //class
//****************************************
<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:id="@+id/head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/header" />
<Button
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="@string/play" />
</RelativeLayout>
No error is indicated in Eclipse. If I run it without the button, it plays.
Do you have any idea what is wrong, and how to fix it?
************************
package com.example.mp3_trial;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity
{
private Button mPlay;
final MediaPlayer medp = MediaPlayer.create(this, R.raw.badbill);
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.activity_main);
mPlay = (Button) findViewById(R.id.play);
/** If I put this here instead of above, Eclipse says medp is not used.
MediaPlayer medp = MediaPlayer.create(this, R.raw.badbill);
*/
mPlay.setOnClickListener(new OnClickListener()
{
public void onClick(View view)
{
medp.start();
}
});
} //bundle
} //class
//****************************************
<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:id="@+id/head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/header" />
<Button
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="@string/play" />
</RelativeLayout>