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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:19:50+00:00 2026-05-25T17:19:50+00:00

Hello Friends, I make one app in android, in which i take three radio

  • 0

Hello Friends,
I make one app in android, in which i take three radio button in radiogroup and take two buttons “play” and “stop”.
my problem is that when i play the song it is playing well but when i click on stop button and then click on play button then song is not playing,
how to do that ? please help me if anybody know.
below is code that i write:

 package com.mediaplayer;

import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class MediaplayerActivity extends Activity implements OnCheckedChangeListener {

MediaPlayer song1,song2,song3;
int whatsong = 0;

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



    RadioGroup rgMusic = (RadioGroup) findViewById(R.id.radioGroup1);

    song1 = MediaPlayer.create(MediaplayerActivity.this, R.raw.fluet);
    song2 = MediaPlayer.create(MediaplayerActivity.this, R.raw.mogra_na_phool);
    song3 = MediaPlayer.create(MediaplayerActivity.this, R.raw.airtel);


    Button bPlay = (Button) findViewById(R.id.bPlay);
    Button bStop = (Button) findViewById(R.id.bStop);

    rgMusic.setOnCheckedChangeListener(this);

    bPlay.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {           

            if(song1.isPlaying())
            {
                song1.pause();
                song1.seekTo(0);
            }

            if(song2.isPlaying())
            {
                song2.pause();
                song2.seekTo(0);
            }

            if(song3.isPlaying())
            {
                song3.pause();
                song3.seekTo(0);
            }

            switch (whatsong) {

            case 1:
                try {
                    song1.prepare();
                } catch (IllegalStateException e) {                 
                    e.printStackTrace();
                } catch (IOException e) {                   
                    e.printStackTrace();
                }
                song1.start();
                break;  

            case 2:
                try {
                    song2.prepare();
                } catch (IllegalStateException e) {                 
                    e.printStackTrace();
                } catch (IOException e) {                   
                    e.printStackTrace();
                }
                song2.start();
                break;

            case 3:
                try {
                    song3.prepare();
                } catch (IllegalStateException e) {                     
                    e.printStackTrace();
                } catch (IOException e) {               
                    e.printStackTrace();
                }
                song3.start();
                break;
            }
        }
    });

    bStop.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {       

            switch (whatsong) {

            case 1:
                song1.stop();
                break;  

            case 2:
                song2.stop();
                break;

            case 3:
                song3.stop();
                break;
            }           
        }
    });                                      
}

@Override
public void onCheckedChanged(RadioGroup group, int rbId) {      

    switch (rbId) {
    case R.id.rbMusic1:
        whatsong = 1;           
        break;
    case R.id.rbMusic2:
        whatsong = 2;           
        break;
    case R.id.rbMusic3:
        whatsong = 3;           
        break;

    }

}

}

  • 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-25T17:19:51+00:00Added an answer on May 25, 2026 at 5:19 pm

    now use this edited code. This code will help you. If it is not running properly inform me.

    package com.mediaplayer;
    
    import java.io.IOException;
    import java.util.ArrayList;
    
    import android.app.Activity;
    import android.media.MediaPlayer;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.RadioGroup;
    import android.widget.RadioGroup.OnCheckedChangeListener;
    
    public class MediaplayerActivity extends Activity implements OnCheckedChangeListener {
    
    MediaPlayer song1;
    int whatsong = 0;
    
    private ArrayList<Integer> songIds;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
    
    
        RadioGroup rgMusic = (RadioGroup) findViewById(R.id.radioGroup1);
    
    
        songIds=new ArrayList<Integer>();
    
        songIds.add(R.raw.fluet);
        songIds.add(R.raw.mogra_na_phool);
        songIds.add(R.raw.airtel);
    
        song1 = MediaPlayer.create(Nothing.this, R.raw.fluet);
    
    
        Button bPlay = (Button) findViewById(R.id.bPlay);
        Button bStop = (Button) findViewById(R.id.bStop);
    
        rgMusic.setOnCheckedChangeListener(this);
    
        bPlay.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {           
    
    
    
                if(song1!=null)
                {
                   song1.release();
                }
    
    
                switch (whatsong) {
    
                case 1:
                    try {
                        song1 = MediaPlayer.create(Nothing.this, songIds.get(0));
                        song1.prepare();
                    } catch (IllegalStateException e) {                 
                        e.printStackTrace();
                    } catch (IOException e) {                   
                        e.printStackTrace();
                    }
                    song1.start();
                    break;  
    
                case 2:
                    try {
                        song1 = MediaPlayer.create(Nothing.this, songIds.get(1));
                        song1.prepare();
                    } catch (IllegalStateException e) {                 
                        e.printStackTrace();
                    } catch (IOException e) {                   
                        e.printStackTrace();
                    }
                    song1.start();
                    break;
    
                case 3:
                    try {
                        song1 = MediaPlayer.create(Nothing.this, songIds.get(2));
                        song1.prepare();
                    } catch (IllegalStateException e) {                     
                        e.printStackTrace();
                    } catch (IOException e) {               
                        e.printStackTrace();
                    }
                    song1.start();
                    break;
                }
            }
        });
    
        bStop.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {       
    
               if(song1!=null){
                   song1.release();
               }
            }
        });                                      
    }
    
    @Override
    public void onCheckedChanged(RadioGroup group, int rbId) {      
    
        switch (rbId) {
        case R.id.rbMusic1:
            whatsong = 1;           
            break;
        case R.id.rbMusic2:
            whatsong = 2;           
            break;
        case R.id.rbMusic3:
            whatsong = 3;           
            break;
    
        }
    
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello friends i am having two frames, each frame has a html form which
• hello friends, • I have one solution say sol1 ’ which contain one
Hello friends can you tell me how to make style of button like hyperlink.
hello friends i m trying to make a inbox system in which we select
Hello friends i am running code given below which contains the setLogTimeEntery function and
hello friends i want to use toggle on <li> when one <li> is open
Hello Friends I am trying to compose two images in imagemagick shell script commane
VS2005, ASP.NET, C#, IIS6 Hello friends, I have a master page divided into three
Hello friends, I am developing an app in Titanium and I have a tableview
Hello Friends i have the following query which defeat the very purpose. A day

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.