com.evolution.player.ui.musicplayer
Class MusicPlayer

java.lang.Object
  extended by com.evolution.player.ui.musicplayer.MusicPlayer

public abstract class MusicPlayer
extends java.lang.Object

A music player can play a given media.

It's guaranteed that the first call on a music player object is a call to open(LocalMediaInfo, IStateCallback) and the last call is a call to stop(), both methods are only called once. start() is always called before stop(). pause() is always called before resume() and only if canPause() is true.

Clients must implement.

Since:
0.4
See Also:
MusicPlayerProvider

Nested Class Summary
static interface MusicPlayer.IStateCallback
          A state callback is used by the player to notify the music player controller about state changes.
 
Constructor Summary
MusicPlayer()
           
 
Method Summary
 boolean canChangeVolume()
          Is this player able to change the volume of the song it plays?
abstract  boolean canPause()
          True if this player is able to pause the playback.
 boolean canSeek()
          Does this music player support seeking?
abstract  void open(LocalMediaInfo info, MusicPlayer.IStateCallback callback)
          Prepare this music player to start playing the given media.
abstract  void pause()
          Pause the playback.
abstract  void resume()
          Resume the playback.
 void seek(int percentage)
          Seek to the given percentage in the file, that is 0 is the beginning, 100 the end and 50 is the middle of the song.
 void setVolume(int volume)
          Set the volume of the current song.
abstract  void start()
          Start playing the media.
abstract  void stop()
          Stop playing the media.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MusicPlayer

public MusicPlayer()
Method Detail

open

public abstract void open(LocalMediaInfo info,
                          MusicPlayer.IStateCallback callback)
                   throws java.io.IOException
Prepare this music player to start playing the given media. The music player controller must be notified about state changes through the given state callback. Throw an IOException if the media can not be opened for some reason.

Parameters:
info - the media to be played
callback - the callback to notify about state changes
Throws:
java.io.IOException - if the media can not be read

start

public abstract void start()
Start playing the media.


stop

public abstract void stop()
Stop playing the media. Dispose any resources. This object will no longer be used.


canPause

public abstract boolean canPause()
True if this player is able to pause the playback.

Returns:
true if this player can pause.

pause

public abstract void pause()
Pause the playback. This is only called if canPause() returns true.


resume

public abstract void resume()
Resume the playback. This is only called after pause() has been called.


canSeek

public boolean canSeek()
Does this music player support seeking?

Returns:
true if this player can seek

seek

public void seek(int percentage)
Seek to the given percentage in the file, that is 0 is the beginning, 100 the end and 50 is the middle of the song.

Parameters:
percentage - the percentage of played time after seek returns

canChangeVolume

public boolean canChangeVolume()
Is this player able to change the volume of the song it plays?

Returns:
true if the player can change the volume

setVolume

public void setVolume(int volume)
Set the volume of the current song. This is only called if canChangeVolume() returns true

Parameters:
volume - the volume in the range [0, 100]