Wednesday 14 August 2013

how to stop audio by clicking button and jumped to other activity (layout)

how to stop audio by clicking button and jumped to other activity (layout)

on one activity an audio is being played. now i want to click on a button
so that audio should stopped and also an other activity opened using
intent. i used .stop() to stop audio. but when i click on button, a
message is shown "unfortunately application has stopped", and my
application is closed, what to do of it???
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener{
Button enterbutton;
MediaPlayer mPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MediaPlayer mPlayer=MediaPlayer.create(this, R.raw.main_act);
mPlayer.start();
enterbutton=(Button)findViewById(R.id.btn_enter1);
enterbutton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
mPlayer.stop();
Intent i=new Intent(MainActivity.this,Select_destination.class);
startActivity(i);
}
}

No comments:

Post a Comment