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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:47:23+00:00 2026-06-08T10:47:23+00:00

I’m working on a media player app that will play music in the background

  • 0

I’m working on a media player app that will play music in the background using a service, but I am confused about all the different ways to communicate with the service. I want the service to tell the activity when it is playing so the button can change to pause. I also want a seek bar so I will need information about what is currently playing in the service.

I have been looking at different examples for a while now and it seems like everyone of them is doing it a different way. Some are binding the activity to the service, some just use global broadcasts, and the android music player is using aidl.

As far as a media player goes, which method should I be using? Is one going to allow me to do stuff that won’t work on the other methods? What did using the aidl allow them to do?

  • 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-06-08T10:47:25+00:00Added an answer on June 8, 2026 at 10:47 am

    I’ve had roughly the same questions over the last several months. It’s not a real easy question to answer because there are several variables that go into the decision. Likely, you’ll end up using a combination of the options.

    Q: Is the communication one way? Just from the service to the activity?
    A: If so, then the LocalBroadcastManager is your friend. I’ve found this to be very useful and one of the easiest ways to communicate from service to activity.

    Q: Do you expect other applications to receive your broadcasts?
    A: If so, then you’ll not be able to use the LocalBroadcastManager. You’ll have to use global ones with Context.sendBroadcast() instead.

    Q: Are you expecting to communicate back to the service from your activity?
    A: This one is tricky. If you just need to tell the service something and don’t expect anything in return then you can just use intents. But, if you need information back from the service then you’ll definitely want to look into binding to that service.

    I’ve found that when binding to your service I sometimes find myself playing a waiting game while the activity binds to the service. So, this can be a little difficult when time is important. You’ll have to work to ensure that you’ve bound to the service well before you expect to communicate with it.

    Given your example and assuming that your not expecting other applications to receive your broadcasts you could do something like the following within your media player service.

    Intent broadcastIntent = new Intent(PlayerService.AUDIO_PLAYING);
    LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent);
    

    Then, within your player activity you need to register as a listener for this intent. Maybe within your onCreate() or onStart(). This can vary depending on your application.

    IntentFilter broadcastsToListenFor = new IntentFilter();
    broadcastsToListenFor.addAction(PlayerService.AUDIO_PLAYING);
    LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver, broadcastsToListenFor);
    

    Your broadcastReceiver would look something like this…

    // Set up broadcast receiver
    private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
    
        @Override
        public synchronized void onReceive(Context context, Intent intent) {
    
            if(action.equals(PlayerService.AUDIO_PLAYING)) {
    
              // Set your play button image to pause here
            }
        }
    };
    

    Finally, make sure that you unregister your activity from receiving these broadcasts in the onStop() or onPause() method. Again, depending on your specific scenario…

    LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
    

    We’ve done something very similar to this recently and it’s working pretty well. I really think it’s worth it to test and play around with each of the options because you’ll probably find a situation where each of them is the right choice.

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

Sidebar

Related Questions

I'm working on an app that will both record an audio file, and then
I've made my app play music in the background, I also successfully made it
I am working on media play app based on this example: How to design
I'm using the MediaPlayer class in an app that I'm currently working on. I
I've been working on a small media player app for Android. I'm having some
I working on a distributed mediaplayer that uses the windows media player component. Now
I am using media element to render video in WPF. All videos are working
I'm currently building an app that will play sounds. When a user starts a
I am working on a Browser-based media player which is written almost entirely in
I'm working on an android media player which needs equalizer. However, equalizer is only

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.