Monday, February 25, 2013
Android Media Player
This document represents the description of a mobile application that is able to act like a media player. The main purpose of the application is to be able to embed an audio file and then play it. The application provides two buttons and a seek bar. The buttons are used for starting, pausing and stopping the song and the seek bar was used for jumping to a specific location of the song.
The program start by creating a MediaPlayer object together with the two buttons and the seek bar. The maximum value of the seek bar is set to the length of the song.
For the buttons to respond to the user input, an OnClickListener event was set for both of them. Each button has a different behaviour depending on its functionality. For example, the Stop button is supposed to call the stop method for the MediaPlayer object when clicked.
One problem encountered during this method was that after the MediaPlayer was stopped, the song was not able to start any more The solution that was found for this problem implies calling a prepare method for the MediaPlayer object after it was stopped. After the Stop button is pressed, the status of the Play/Pause button is set to the Play status. Also, the seek bar is reset to the beginning.
The Play/Pause button is used either to start or to pause the song, depending on the state of the MediaPlayer object. If it is in the playing state, it changes the state of the button to Pause and vice-versa.
The functionality of the seek bar is to allow the user to jump to a specific time of the song. This way, the OnSeekBarChangeListener of the seek bar calls the seekTo method of the MediaPlayer object with the specific progress.
The thread that allows the user to see the actual progress of the song on the seek bar was not implemented yet, but it will be available in future versions.
Source Code at http://ge.tt/4iNVuUZ/v/0?c
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment