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 962187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:27:57+00:00 2026-05-16T01:27:57+00:00

I have a program with a function copied below it plays a sound upon

  • 0

I have a program with a function copied below it plays a sound upon clicking a button. If you click the button 10 times 10 different media players play the same sound that is the way i want it but how can i assign a button to stop all 10 media players at a time like a “STOP ALL BUTTON”

public void onClick(View v){
 int resId = 0;
 int stopped = 0;
 switch (v.getId()){
 case R.id.Wail:
  resId = R.raw.fedsigwail;
  break;
 case R.id.Yelp:
  resId = R.raw.fedsigyelp;
  break;
 case R.id.HiLow:
  resId = R.raw.hilow;     
  break;
 case R.id.FederalQ:
  resId = R.raw.federalq;
  break;
 case R.id.Horn:
  resId = R.raw.fedsignhorn;
  break;
 case R.id.STOPALL:
  mp.stop();
  mp.release();
  stopped = 1;
  break;
 }

 if (stopped != 1){
 mp = MediaPlayer.create(this, resId);
 mp.start();
 }


}

The code above only stops the last instance of mp.

Any Input would be appreciated

  • 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-16T01:27:58+00:00Added an answer on May 16, 2026 at 1:27 am

    mp.stop(); only stops one instance of a media player, since mp can only be one mediaplayer instance.
    If mp is one of your media players, where are the other ones? You mentioned you have

    10 different media players

    so I would expect something like mp1, mp2, mp3, …, mp10. But right now it seems you actually only using one media player instance, or at least stopping it.

    With each call of

    mp = MediaPlayer.create(this, resId)
    

    you lose the reference to the previous created media player, since you ‘override’ it with a newly created instance.
    You need to keep a reference to all your created media players, i.e. via an ArrayList or HashMap or similar.

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

Sidebar

Related Questions

I have this function: Program A public ICollection<ReportLocationInfo> GetAllReportsInstalled() { return _Reports; } I
I have a program in Octave that has a loop - running a function
On my program I have a function that checks for the current version of
I have a C program which has a function call that is defined in
I have a python program which calls a C function. I send some structures
In my program I have coded the following private variables and function. private string
I have a popup function in a program that works well, be re-loads the
I have a utility function in my program for searching for entities. It takes
I am currently trying to build a program where I have a recursive function
It's a very simple program. I have a function defined on the top and

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.