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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I have had luck doing a look ahead for the… May 16, 2026 at 10:11 am
  • Editorial Team
    Editorial Team added an answer Use overflow: scroll instead of overflow: auto - that'll force… May 16, 2026 at 10:11 am
  • Editorial Team
    Editorial Team added an answer answerText is the name of the label? then what are… May 16, 2026 at 10:11 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

[Updated]: Answer inline below question I have an inspecting program and one objective is
We have a VB.NET program that needs to periodically call a function in an
I'm a PHP newbie. I'm trying to use preg_match_all function in the below program
I have a C/ncurses program that I'm debugging/maintaining. This program does ripoffline twice: first,
I have a program where i simply copy a byte array into a long
I have a object that is my in memory state of the program and
When I include some function from a header file in a C++ program, does
Assume that i have written a program in C++ without using RTTI and run-time
I am trying to have the function toggleClick return powerData. I need to store
I am new at haskell, I have to write a program context-aware,so I thought

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.