Go Back   Android Forums > Android Discussion > Android Applications
Android Applications All the information you could ever want about Android Applications. Learn about apps and get help with them... all here! New apps can be found and announced in the Applications Announcements forum linked below.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old August 21st, 2011, 04:22 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2011
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Question How to use MediaPlayer mp.stop(); help

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

JohnsenAndreas is offline  
Reply With Quote
sponsored links
Reply
Tags
java, mediaplayer, sound, start, stop


Go Back   Android Forums > Android Discussion > Android Applications
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 09:39 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.