Having problems with simple code
Hello,
I am very new to java programming and I am attempting to create a simple soundboard as a starter project. I have already created my raw folders and have all my files in the correct folder. I have my main.xml setup and my layout prepared with the graphics icons etc. Just the last part I cannot figure out I have compiled my code perfectly with no errors. I am using eclipse to create the app but when I test it on my tablet or using an emulator everything looks fine but the sound will not play. I have attempted with mp3,WAV, and ogg formats as well with different sounds. I dont know what I am doing wrong I will include my code if someone could help me out would be greatly appreciated as I have posted this problem on 5 different forums and nobody will help me.
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;
/** Called when the activity is first created. */
@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("All Night Long");
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.yougotamessage);
mpAudio.setLooping(true);
}
public void onClick(View v) {
if (v==bPlay){
mpAudio.start();
}else if(v==bPause) {
mpAudio.pause();
}
}
}
Please Help!
Re: Having problems with simple code
You're probably better off looking for an android-specific forum, because any advice you get here is going to be very basic. We're much better at answering general java questions than platform-specific ones.
To begin with I'd suggest trying to trace what your program is doing. For example, I'd assume the emulator has some way of showing debug output or stopping at breakpoints. You might want to try printing something or setting a breakpoint at the beginning of the onClick method, just to see whether it actually gets called. If it does, check whether either of the if statements is true when it's called.
Re: Having problems with simple code
Hello,
Thanks for replying to me, I already look for a android forum found about 4 posted in all of them and no one answered me except 1 guy who was a complete ass and didnt tell me anything except to get off that forum pretty much. The platform I am running does have a trace method so I will try that out and see what happens. Thanks again for the reply.
Quote:
Originally Posted by
Singing Boyo
You're probably better off looking for an android-specific forum, because any advice you get here is going to be very basic. We're much better at answering general java questions than platform-specific ones.
To begin with I'd suggest trying to trace what your program is doing. For example, I'd assume the emulator has some way of showing debug output or stopping at breakpoints. You might want to try printing something or setting a breakpoint at the beginning of the onClick method, just to see whether it actually gets called. If it does, check whether either of the if statements is true when it's called.
Re: Having problems with simple code
Please go through the Forum Rules -- particularly the third paragraph.
db