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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:00:11+00:00 2026-05-25T13:00:11+00:00

I am working in android. I am creating a mediaPlayer which is running audio

  • 0

I am working in android. I am creating a mediaPlayer which is running audio files. i have 10 buttons. i have assigned different url to each button. So when i press button1 then song of url with respect to button 1 is playing. and then i click on 2nd button then song of button 2 is also playing with song 1. but i want to stop song of button 1 when i press button 2.

this is the code i am using for this functionality:-

  public void onClick(View v)
 {

        MediaPlayer mediaPlayer=new MediaPlayer();

        if (mediaPlayer.isPlaying()) 
        {
            mediaPlayer.stop();
            mediaPlayer.release();

        } 

        int i = Integer.parseInt((v.getTag()).toString());
        String str=urls[i];
        try {




                mediaPlayer.setDataSource(str);
        mediaPlayer.prepare();
        mediaPlayer.start();

         } catch (Exception e)
               {
                e.printStackTrace();
        }

    }

please check my code and let me know what is mistake done by me.

  • 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-25T13:00:12+00:00Added an answer on May 25, 2026 at 1:00 pm

    you have construct a new MediaPlayer object each time the user click you view

    how could it be in the running state !!!

    calling release() method on a MediaPlayer object it is in thre End state
    Once the MediaPlayer object is in the End state, it can no longer be used and there is no way to bring it back to any other state.

    but in case you want to reuse a MediaPlayer object you should call the
    call the following method in the same order

    reset()
    make the mediaPlayer enter the Idle state

    setDataSource()
    set your data source note : the mediaplayer shoud be in the idle state

    prepare()

    start()

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

Sidebar

Related Questions

Hi I am creating GridView from url in android,everything is working scrolling is not
i am working on android. i am creating a login button. i want that
I am working on Android , I am creating a player for audio songs.
I just started working with Android and I have a problem with my map.
I am working on an Android project where a group of buttons needs to
I have been working on a Android Web Services program that uses a number
I'm creating my first android app (or attempting to anyway) and i have a
I am creating an android app which pulls in RSS Feeds from here http://spaceflight1.nasa.gov/realdata/sightings/cities/rss/index.cgi?country=United_Kingdom&region=England&city=Manchester
I am working on my first ever android app, and I'm creating basic exercise/calorie
I am working on a shopping cart application for Android. While creating package design,

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.