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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:41:05+00:00 2026-06-16T21:41:05+00:00

I am new to Android. I am creating service for Media Player so that

  • 0

I am new to Android. I am creating service for Media Player so that it can continue to play song even if i close the application. I have created activity for Media Player and it is having all the functionality like play , pause , next , previous , seekbar and also includes oncompletionlistener . All works excellent. But Now i want that all should be managed by service.

I have Created MyService Class :

public class MyService extends Service {

    public static MediaPlayer mp;

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onCreate() {
        mp = new MediaPlayer();     
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {  
        return START_STICKY;
    }

But in my player activity i have created ArrayList for Songlist from which i am taking currentsongIndex and through it i am maintaining all the functionality like next , previous and all.. Now in service how do i get songlist which is also required in my activity ?? Where should i create MediaPlayer object mean in service or activity ??

for MediaPlayer I have reffered http://www.androidhive.info/2012/03/android-building-audio-player-tutorial/ . For my media player code you can refer this site. Thanks.
Pleaze clear my doubt. I am so confused. Reply me soon..

  • 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-16T21:41:06+00:00Added an answer on June 16, 2026 at 9:41 pm

    You are on the right track. I have adapted from the SDK Samples; this is how I do it and it works great.
    From your ArrayList (in your activity NOT from the Service) call

    onListItemClick
    

    and start an intent that starts the music service:

    startService(new Intent(MusicService.ACTION_PLAY));
    

    In your manifest you will need to add:

     <intent-filter>
                <action android:name="com.blah.blah.action.PLAY" />
               <xxx xxx> 
     </intent-filter>
    

    And of course in your Music Service you need to receive the Intent:

    public int onStartCommand(Intent intent, int flags, int startId) {
        String action = intent.getAction();
        if (action.equals(ACTION_PLAY))
            processPlayRequest();
      }
    

    Be sure to add Intents for skip, rewind, stop etc.
    Let me know if this helps.

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

Sidebar

Related Questions

i am creating a new android application.i am using the table layout. I have
I'm New to android, and I'm creating an application that uses the twitter api,
I am creating an Android application that connects to the Fogbugz XML API (sends
I am creating an Android application using GreenDAO ORM, with a genericized crud service
I am creating an android application in which i have to get the current
I am creating an Android app that will have a chat function. I plan
I am creating an application that will have multiple images on the screen, these
Suppose I am creating an Android application that's like an SMS app. The requirements
While creating a new android project in eclipse 3.5, i have selected Android 2.1
I am new to android development. I am creating an android application, in which

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.