Results 1 to 4 of 4
Thread: Having problems with simple code
- 06-27-2012, 03:22 AM #1
Member
- Join Date
- Jun 2012
- Posts
- 2
- Rep Power
- 0
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!
- 06-27-2012, 09:31 AM #2
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
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.If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
- 06-27-2012, 03:22 PM #3
Member
- Join Date
- Jun 2012
- Posts
- 2
- Rep Power
- 0
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.
- 06-28-2012, 08:59 PM #4
Re: Having problems with simple code
Please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Simple Homework applet problems
By ADustedEwok in forum Java AppletsReplies: 1Last Post: 12-08-2011, 10:11 PM -
I'm having problems with my simple prompting program.
By ziongio in forum New To JavaReplies: 4Last Post: 01-21-2011, 10:43 PM -
A few problems with my code..
By Kerrai in forum New To JavaReplies: 1Last Post: 10-25-2010, 07:49 PM -
Two simple array problems.
By DMiller in forum New To JavaReplies: 4Last Post: 11-06-2009, 11:50 AM -
Problems with code
By jforce93 in forum New To JavaReplies: 8Last Post: 08-14-2009, 02:49 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks