Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6534721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:17:06+00:00 2026-05-25T10:17:06+00:00

I am having a couple problems I could really use some help on both.

  • 0

I am having a couple problems I could really use some help on both. The first is I am trying to get an audio file to play when the application is started and as soon as the shake occurs it stops. (It is not playing it at all on either screen it is supposed to). The other issue I am having is when I shake the phone an audio is supposed to play. It is doing just that, but the problem is that at the end of the audio playing it make a pop sound. That noise isn’t on the audio files so I am not exactly sure where that sound is coming from. Any help would be appreciated. Thanks in advance.

public class Ask extends Activity{
private SensorManager mSensorManager;
 private ShakeEventListener mSensorListener;
 String[] answer;
 int possibleAnswers, randomAnswer, talkRun=0;
 long lastClick;


 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ask);

        final Random generator = new Random();




        //Sounds
        final SoundPool sounds = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
        final int sound0 = sounds.load(this, R.raw.coughing, 1);

        final int sound25 = sounds.load(this, R.raw.askbud, 1);


        sounds.play(sound25, 1f, 1f, 1, 0, 1f);

        mSensorListener = new ShakeEventListener();
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mSensorManager.registerListener(mSensorListener,
            mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_UI);

      final TextView tv = (TextView)findViewById(R.id.answer);


        mSensorListener.setOnShakeListener(new ShakeEventListener.OnShakeListener() {

          public void onShake() {
              if (System.currentTimeMillis() - lastClick > 500) {
                  lastClick = System.currentTimeMillis();
                      sounds.stop(sound25);
                    sounds.stop(sound0);


                      randomAnswer = generator.nextInt(possibleAnswers);


                      if(randomAnswer==0){
                         sounds.play(sound0, 1f, 1f, 1, 0, 1f);
                      }

              }
          }
        });
    }





 @Override
  protected void onResume() {
    super.onResume();
    mSensorManager.registerListener(mSensorListener,
        mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
        SensorManager.SENSOR_DELAY_UI);
  }

  @Override
  protected void onStop() {
    mSensorManager.unregisterListener(mSensorListener);
    super.onStop();
  }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:17:07+00:00Added an answer on May 25, 2026 at 10:17 am

    I fixed it by switching from using sound pool to using media player. Also got to make sure to release() or it was causing other problems like the sound stopped playing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using XSLT and having great success, just got a couple of problems. Warning:
For the last couple months i have ben having some issues with my app.config
Hello i am having some problems generating random numbers with C# Now i have
I am having a couple of problems recording sound on a device. The code
I'm kind of a new programmer, and I'm having a couple of problems with
just a few questions that I thought I could use some light on. So
I've been going at this problem for a solid couple hours now and having
I am having a couple of issues deciding how best to describe a certain
I'm having a couple of issues which may be related, or may not. I
I've been profiling an application all day long and, having optimized a couple bits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.