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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:50:56+00:00 2026-06-05T18:50:56+00:00

So I’m creating an application for my mobile programming class and I’m running into

  • 0

So I’m creating an application for my mobile programming class and I’m running into difficulties with the “play” portion of it. To give you some context: basically we need to create a basic audio player that downloads an mp3 from a predefined source and then play that mp3, among other things. I’ve correctly set up the download service but I’m confused why my code for playing the file isn’t working. In my main.java I have a slew of anon. onclick listeners for the UI’s buttons and then a switch statement in my mediaplayer service to figure out which button was clicked.

Here’s my onclick for the play option from my main activity:

play.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), PlayService.class);
            File path = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
            File file = new File(path, "Bob_Marley-Jammin.mp3");
            intent.putExtra("path", file);
            intent.putExtra("key", 0);
            startService(intent);               
        }
    });

and here’s the download onclick:

 download.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), DownloadService.class);
            intent.putExtra("url", "https://dl.dropbox.com/s/6e6pn43916nl10i/Bob_Marley-Jammin.mp3?dl=1");
            startService(intent);               
        }
    });

and here’s my PlayService:

package com.connor.black;

import java.io.IOException;

import android.app.IntentService;
import android.content.Intent;
import android.media.MediaPlayer;

public class PlayService extends IntentService{

public PlayService() {
    super("PlayService");
}

public MediaPlayer mMediaPlayer;
public String path;

@Override
protected void onHandleIntent(Intent intent) {
    path = intent.getStringExtra(path);
    int key = intent.getIntExtra("key", 0);
    mMediaPlayer = new MediaPlayer();

    switch (key) {
    case 0: //Play
        if (mMediaPlayer.isPlaying())
            break;
        else{
            try {
                mMediaPlayer.setDataSource(path);
            } catch (IllegalArgumentException e1) {
                e1.printStackTrace();
            } catch (SecurityException e1) {
                e1.printStackTrace();
            } catch (IllegalStateException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            try {
                mMediaPlayer.prepare();
            } catch (IllegalStateException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
                mMediaPlayer.start();
        }
        break;
    case 1: //Pause
        if(mMediaPlayer.isPlaying())
            mMediaPlayer.pause();
        break;
    case 2: //Stop
        if(mMediaPlayer.isPlaying()){
            mMediaPlayer.pause();
            mMediaPlayer.seekTo(0);
        }
        break;
    default:
        break;
    }

}

}

Basically the file downloads correctly but when I press the “play” button nothing happens.

  • 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-05T18:50:58+00:00Added an answer on June 5, 2026 at 6:50 pm

    Is your function called? Use Log.d to check. Is your path to the mp3 correct?

    The following small snippet plays an MP3 (change the path to your file)

    package com.aplayer;
    
    import android.app.Activity;
    import android.media.MediaPlayer;
    import android.net.Uri;
    import android.os.Bundle;
    
    public class APlayerActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
    
            MediaPlayer mMediaPlayer = new MediaPlayer();
    
            Uri data;
            data = Uri.parse("/sdcard/jazz.mp3");
    
            mMediaPlayer = MediaPlayer.create(getBaseContext(), data);
            mMediaPlayer.setLooping(false); // Set looping
            mMediaPlayer.start();
    }
    

    }

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

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.