Jump to content
Android Forum - A Community For Android Users and Enthusiasts

Adding sounds to buttons help


Recommended Posts

Hello,

I am new to android development and need some help creating a sound testboard, to my knowledge my code should be perfect and work but when I run it in the emulator or on my tablet the sound doesnt work. If anyone can help would really appreciate it. Below is my code:

 

package your.test.namespace;

 

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;

import android.widget.LinearLayout;

 

public class TestsoundboardActivity extends Activity implements OnClickListener{

 

Button bPlay;

Button bPause;

MediaPlayer mpAudio

 

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

 

LinearLayout layout = new LinearLayout(this);

 

Button bPlay = new Button(this);

 

bPlay.setText("Play");

 

bPlay.setOnClickListener(this);

 

Button bPause = new Button(this);

 

bPause.setText("Pause");

 

bPause.setOnClickListener(this);

 

layout.addView(bPlay);

layout.addView(bPause);

 

setContentView(layout);

 

mpAudio = MediaPlayer.create(this,R.raw.killer);

 

mpAudio.setLooping(true);

 

 

}

 

public void onClick(View v) {

 

if (v==bPlay){

mpAudio.start();

}else if(v==bPause) {

mpAudio.pause();

}

 

}

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...