• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Unfortunately prog stopped

Davemar

Lurker
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>
 
This is the configuration that plays.
*************
package com.example.playmp3;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

MediaPlayer medp = MediaPlayer.create(this, R.raw.badbill);
medp.start();
} //bundle
} //class
 
Never mind, guys ... I tried this and it works.
Now all I have to do is add pause, resume, stop, whatever buttons.

******************
package com.example.player456;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity
{
MediaPlayer medp;

@Override
protected void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

medp = MediaPlayer.create(MainActivity.this,R.raw.badbill);
Button mPlay = (Button) findViewById(R.id.btnPlay);

mPlay.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
medp.start();
}
});
}
}
 
Back
Top Bottom