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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:22:52+00:00 2026-05-27T09:22:52+00:00

I have an activity that is a service which plays audio using a media

  • 0

I have an activity that is a service which plays audio using a media player. This is the service

class MusicService extends Service implements OnCompletionListener {
 MediaPlayer mediaPlayer;

 @Override
public IBinder onBind(Intent intent) {
return null;
}

 @Override
 public void onCreate() {
  mediaPlayer = MediaPlayer.create(this, R.raw.s);// raw/s.mp3
  mediaPlayer.setOnCompletionListener(this);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (!mediaPlayer.isPlaying()) {
  mediaPlayer.start();
}
return START_STICKY;
 }

  public void onDestroy() {
   if (mediaPlayer.isPlaying()) {
  mediaPlayer.stop();
   }
   mediaPlayer.release();
 }

 public void onCompletion(MediaPlayer _mediaPlayer) {
stopSelf();
 }

}

Instead of playing from that raw file i want it to play from a path that is a String that comes from the sd card. the path is held in the class that calls the service how do i pass that string to the service class and put it in the mediaplayer create method. here is where i call the service

   private void playAudio(String url) throws Exception{
Intent music = new Intent(this,MusicService.class);
startService(music);

}

  • 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-27T09:22:53+00:00Added an answer on May 27, 2026 at 9:22 am

    Use the putExtra commands of the starting Intent:

    music.putExtra(key, value);
    

    Then get that passed info in the onStartCommand of your mediaplayer service:

    intent.getExtras().getString(key);
    

    Beware that this intent can be null in cases when the service is restarted by the system.

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

Sidebar

Related Questions

I have an Activity calling a Service defined in IDownloaderService.aidl: public class Downloader extends
this is the current state/situation: I have an Activity which binds a Service which
I start an activity in my class Locator.java which starts a locacionListener Service. That
I have an activity that starts a long-running service which in turn adds an
I have an Activity that retrieves data from a web service. This data is
This seems like a simple problem: I have a WF4 activity that guides the
I have my remote service which tries to run an activity from a different
I have an Activity (A) and a Service (S) which gets started by A
I need to have a class with one activity that is performed once per
suppose that you have two activities A(which is the main activity) and B when

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.