Hello forum!
I have spent hours trying to make a button that can play sound and if i click it again the sound will stop. I have only managed to get the sound playing. If i use mp.stop(); the sound will not start at all...
my source code is:
package AndreasJohnsen.buttonstartstop;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class buttonstartstopActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final MediaPlayer mpButtonOn = MediaPlayer.create(this, R.raw.cuttersound);
//CuttersoundButtonLink
Button ButtonOn = (Button) findViewById(R.id.button1);
ButtonOn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mpButtonOn.start();
}
});
}
}
reegards Andreas Johnsen
I have spent hours trying to make a button that can play sound and if i click it again the sound will stop. I have only managed to get the sound playing. If i use mp.stop(); the sound will not start at all...
my source code is:
package AndreasJohnsen.buttonstartstop;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class buttonstartstopActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final MediaPlayer mpButtonOn = MediaPlayer.create(this, R.raw.cuttersound);
//CuttersoundButtonLink
Button ButtonOn = (Button) findViewById(R.id.button1);
ButtonOn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mpButtonOn.start();
}
});
}
}
reegards Andreas Johnsen