• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Media Player Android Sample

Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This tutorial will help you how to create a simple Audio Player application.Normally,when you make a player application based on Activity, it will stop when you exit the application. So, now you will know about a technique using Service to perform playing sound. You can play music when your application is closed.

1. MediaPlayer class

MediaPlayer class can be used to control playback of audio/video files and streams. And here is some method is used to control a mediaplayer object.

mp.reset():Resets the MediaPlayer to its uninitialized state.
setDataSource(String path): Sets the data source (file-path or http/rtsp URL) to use.
mp.prepare():Prepares the player for playback, synchronously. After setting the datasource and the display surface, you need to either call prepare() or prepareAsync(). For files, it is OK to call prepare(), which blocks until MediaPlayer is ready for playback.
mp.start():Starts or resumes playback. If playback had previously been paused, playback will continue from where it was paused. If playback had been stopped, or never started before, playback will start at the beginning.
mp.getDuration():Gets the duration of the file(Return the duration in milliseconds)
mp.isPlaying():Checks whether the MediaPlayer is playing.
mp.stop():Stops playback after playback has been stopped or paused.
mp.release():Releases resources associated with this MediaPlayer object.

2. Service class

Service class: A Service is an application component representing either an application’s desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use. Each service class must have a corresponding declaration in its package’s AndroidManifest.xml. Services can be started with Context.startService() and Context.bindService().

3. SongProvider class

Download Sample Source code

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great App.

Could you please help me getting this app run audio files from raw/assets folders instead of sdcard ?

thanks in advance.
A tiny monkey bit me and I got tiny ads:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic