Template

A template of the full project is provided. Revise the Layout files and Java files where noted. You may also revise strings.xml and the Manifest file. You may also need to add files or Java classes.

Links

NPR "Tiny Desk Concerts - Audio" page:
https://www.npr.org/podcasts/510306/tiny-desk-concerts-audio

Sample Concert by Adele:
https://www.npr.org/2011/02/17/133687905/adele-tiny-desk-concert

MP3 link for the Sample Concert by Adele:
https://ondemand.npr.org/anon.npr-mp3/npr/asc/2011/02/20110213_asc_adele.mp3

You can use any MP3 from NPR Tiny Desk Concerts or another source as long as it is publicly available and you have permission.

User Interface

MainActivity

  • Buttons
    • Play Button - Disabled when music is playing, enabled when paused or stopped
    • Stop Button - Disabled when music is stopped, enabled when playing or paused
    • Can implement a "stop()", or pause() and restart song to beginning

DownloadSongDialog - Allow user to enter url for song

  • Can use any method to display to user (Dialog, DialogFragment, Fragment, etc)
  • Once the user enters the url, clicking "Download" starts the DownloadSongService and passes the url

DownloadSongService - IntentService used to download song given URL from DownloadSongDialog

  • Started by DownloadSongDialog once URL is entered
  • Downloads file and starts notification which displays message and contains URI to local file path

MyMediaService - Extends Service, simply contains MediaPlayer

  • Receives commands from MainActivity (play, pause, stop, and possibly init) and performs actions on MediaPlayer
  • Can send MyMediaService the URI for song when play button is pressed or when download notification is clicked (init command)

Notifications

  • Download Started - Display notification when download begins, this does not need to have an action when clicked
  • Download Complete - Display notification when download completes
    • Clicking notification starts MainActivity with the URI to file, song title, and artist name
  • Song playing - Display notification when song is playing
    • Clicking on song reopens application and does not interrupt MediaPlayer
    • When song is paused or stopped, notification should be removed

Options Menu

  • A Download option that will open DownloadSongDialog
  • An Exit button that will
    • Exit the app
    • Stop the MediaPlayer service
    • Don't stop the Download Service

If the user exits the Activity by pressing the home key or back key, then returns to the Activity, the Play, Pause, and Stop Buttons should still work as expected

Things to Note

1. Your Activity should not actually play the music itself, that's what your Service is for. Clicking on the playback Buttons from within your Activity should make calls to the Service, and the Service should take the appropriate action. This prevents playback from being stopped when your Activity loses focus

2. Do not place the MP3 inside of your res/raw directory. You're supposed to download it, then get the URI after the download, and use the URI to launch the MediaPlayer. However, you can use this for testing your MyMediaService

Complete the following tasks:

1. Add a SeekBar to your Activity

  • The SeekBar should be synced with the song (use an AsyncTask)
  • When the user changes the progress on the SeekBar, the song should seek to the correct position
  • The SeekBar progress should balance with the length of the song
  • e.g. if a song is 120 seconds long
    • Moving the progress of the SeekBar to the middle of the SeekBar should seek to (or at least close to) the 60 second mark of the song
  • Stopping the song should send the ProgressBar back to 0

2. Make your app one of the default apps for music playback and keep a list of the tracks that were loaded

  • It should be able to play any MP3 selected on the system
    • For example, if you download an MP3 using the default browser, clicking on the downloaded file should launch your app
  • You'll need to set up an IntentFilter for your Activity
    • You'll need to do some research to figure out how to set up your < intent-filter>
  • You can use SharedPreferences to store information for the songs loaded via your app
  • You should have something like a ListView that shows the user a list of songs that can be played
    • clicking on an item in the list should playback the music using your app as expected
  • In this case, you can just show a default image for the album cover
  • You'll need show the correct title for the song being played (maybe the raw filename)

3. Add a Timer to your Activity using TextViews

  • The Timer should be synced with the song (use AsyncTask)
  • e.g., 90 seconds through the song, the TextViews should represent 1:30
  • When the stop Button is pressed, the timer should go back to 0:00
  • Of course, this one is easier than adding a SeekBar to your Activity
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.