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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:27:26+00:00 2026-05-26T04:27:26+00:00

I have an application from where a play a radio stream using a service

  • 0

I have an application from where a play a radio stream using a service for the media player, that works the next way:
as it starts it calls the service and the radio starts playing, in the main view I have a play and stop button, so when the app starts since the radio starts right away I have set the play button GONE and the Stop button VISIBLE. so if I press the stop button it stops the service and makes the play button VISIBLE and the Stop button GONE, and the other way around.
And so far if the service detects an error it send a Toast plus an update to my notification bar, but the Stop button continues to be VISIBLE and the Play button is still GONE, so my question is how can I make my service at detection of the error make the buttons change? so I could have the Play button VISIBLE and the Stop GONE to try again.
this is how I have code the buttons in OnCreate in my main Activity:

 Button playBtn = (Button) findViewById(R.id.buttonPlay);
    playBtn.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {

             View b = findViewById(R.id.buttonPlay);
                b.setVisibility(View.GONE);

                View c = findViewById(R.id.buttonStopPlay);
                c.setVisibility(View.VISIBLE);

                    TextView textRadioName = (TextView)   findViewById(R.id.textView);
                    textRadioName.setText("You are listening Radio!");
                    startService(new Intent("PLAY"));
                    start();

    }});

    Button stopBtn = (Button) findViewById(R.id.buttonStopPlay);
    stopBtn.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        View b = findViewById(R.id.buttonStopPlay);
        b.setVisibility(View.GONE);

        View c = findViewById(R.id.buttonPlay);
        c.setVisibility(View.VISIBLE);

            TextView textRadioName = (TextView) findViewById(R.id.textView);
        textRadioName.setText("Listen Radio Here");

        pause();
    }});

and this is how I code the error in my MediaPlayer Service:

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
    Toast.makeText(this, "Radio not connected!...." , Toast.LENGTH_LONG) .show();
    StreamError = true;
    updateNotification("Radio not connected!");
    return false;
}

I like the way it works but it looks odd having my stop button VISIBLE and not the play one, so far if I press the stop it makes my play appear and then I can try again! but is not how an application should work right?
Thanks for your time. I hope someone can show me the way.

  • 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-26T04:27:27+00:00Added an answer on May 26, 2026 at 4:27 am

    You can bind to your service, which will return an IBinder that you have to implement. Inside you IBinder you can put a function like:

    public void setPlayer(IPlayer player);
    

    Where your IPlayer would have the set of functionality you want to call from the service. This is where you could put the code to hide the stop button, show the play button, or anything else you want to do from the Service.

    As requested, a link to the sample in the docs: http://developer.android.com/reference/android/app/Service.html#LocalServiceSample

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

Sidebar

Related Questions

I have made a Android streaming application that plays media from online URL's. For
I have an application that uses a BackgroundWorker to play files from a list.
I have an application on one domain that displays content from another application from
I have a web application from a company that has gone out of business.
I have a Play! application and from the JavaScript we now have run in
I have an application that processes data from bluetooth and send it to the
I currently have an application that calls creates and displays charts from various objects'
I have a requirement to play YouTube video content from within an Android application
Background: I have an application which plays video files from disc. When I play
I'm trying to launch an intent from my application that will play audio from

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.