Results 1 to 4 of 4
  1. #1
    Lgood1984 is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default 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!

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default 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!

  3. #3
    Lgood1984 is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default 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 View Post
    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.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: Having problems with simple code

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Simple Homework applet problems
    By ADustedEwok in forum Java Applets
    Replies: 1
    Last Post: 12-08-2011, 10:11 PM
  2. Replies: 4
    Last Post: 01-21-2011, 10:43 PM
  3. A few problems with my code..
    By Kerrai in forum New To Java
    Replies: 1
    Last Post: 10-25-2010, 07:49 PM
  4. Two simple array problems.
    By DMiller in forum New To Java
    Replies: 4
    Last Post: 11-06-2009, 11:50 AM
  5. Problems with code
    By jforce93 in forum New To Java
    Replies: 8
    Last Post: 08-14-2009, 02:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •