org.qtunes.player.spi
Class PlayerImpl

java.lang.Object
  extended by org.qtunes.player.spi.PlayerImpl
All Implemented Interfaces:
java.lang.Runnable, Listener, Service, Player

public class PlayerImpl
extends java.lang.Object
implements Player, java.lang.Runnable, Listener

A Player plays tracks to one or more speakers (technically a SourceDataLine which may be a local speaker, an Airtunes speaker or some other type (eg RTSP, uPnP etc.) Each player maintains it's own playlist and tracks may be cued, reordered, skipped and so on as you'd expect.


Constructor Summary
PlayerImpl()
           
 
Method Summary
 void addSpeaker(Speaker speaker)
          Add a Speaker to the Player.
 java.util.Collection<Speaker> getAvailableSpeakers()
          Get the collection of speakers that could be used by this Player and that aren't currently in use elsewhere.
 ServiceContext getContext()
          Return the ServiceContext that was passed into Service.startService(org.qtunes.core.ServiceContext)
 Track getCurrentTrack()
          Return the currently playing Track, or null if no track is playing
 int getCurrentTrackIndex()
          Return the index in the list of tracks returned from Player.getPlaylist() that is currently playing.
 java.lang.String getDisplayName()
          Return a nice name for this Player for display to the user
 ManualPlaylist getPlaylist()
          Return the Playlist
 long getRemaining()
          Return the number of milliseconds remaining in the playlist.
 int getRepeat()
          Get the repeat mode, as set by Player.setRepeat(int)
 int getRevision()
          Return the revision number.
 boolean getShuffle()
          Get the shuffle mode, as set by Player.setShuffle(boolean)
 java.util.Collection<Speaker> getSpeakers()
          Return the list of Speaker objects current in use by this Player
 int getTrackPosition()
          Return the number of milliseconds into the currently playing track.
 int getVolume()
          Return the current volume
 void handleEvent(java.lang.String name, java.util.Map<?,?> properties)
           
 boolean isPaused()
          Return true if the player is paused, false if it's playing or stopped.
 void playNext()
          Skip to the next track in the playlist.
 void playPrevious()
          Skip to the previous track in the playlist.
 void removeSpeaker(Speaker speaker)
          Remove a Speaker to the Player.
 java.util.Map<java.lang.String,java.lang.Object> reportState()
          Return a Map describing the state of this Service, for serialization back to any client that needs to know (eg webplayer) - so values should be serializable objects, eg Lists, Maps or simple objects.
 void run()
          The main play thread.
 void seek(int ms)
          Seek to the specified millisecond value in the current track If the value is outsize the valid range this method does nothing
 void setCurrentTrackIndex(int ix)
          Set the currently playing track
 void setPaused(boolean paused)
          Set the player to be paused (true) or playing (false).
 void setRepeat(int repeat)
          Set the style of repeat - none (0), track only (1) or playlist (2)
 void setShuffle(boolean shuffle)
          Set whether to shuffle the playlist
 void setVolume(int volume)
          Set the current volume
 void startService(ServiceContext context)
          Start the Service
 void stop()
           
 void stopService(ServiceContext context)
          Stop the Service
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlayerImpl

public PlayerImpl()
Method Detail

run

public void run()
The main play thread. Should be bulletproof

Specified by:
run in interface java.lang.Runnable

playNext

public void playNext()
Description copied from interface: Player
Skip to the next track in the playlist. If there are no more tracks in the queue, stop playing

Specified by:
playNext in interface Player

playPrevious

public void playPrevious()
Description copied from interface: Player
Skip to the previous track in the playlist. If you are currently playing the first track, restart it.

Specified by:
playPrevious in interface Player

setCurrentTrackIndex

public void setCurrentTrackIndex(int ix)
Description copied from interface: Player
Set the currently playing track

Specified by:
setCurrentTrackIndex in interface Player

stop

public void stop()

seek

public void seek(int ms)
Description copied from interface: Player
Seek to the specified millisecond value in the current track If the value is outsize the valid range this method does nothing

Specified by:
seek in interface Player

setPaused

public void setPaused(boolean paused)
Description copied from interface: Player
Set the player to be paused (true) or playing (false).

Specified by:
setPaused in interface Player

isPaused

public boolean isPaused()
Description copied from interface: Player
Return true if the player is paused, false if it's playing or stopped.

Specified by:
isPaused in interface Player

getTrackPosition

public int getTrackPosition()
Description copied from interface: Player
Return the number of milliseconds into the currently playing track.

Specified by:
getTrackPosition in interface Player

getRemaining

public long getRemaining()
Description copied from interface: Player
Return the number of milliseconds remaining in the playlist.

Specified by:
getRemaining in interface Player

setShuffle

public void setShuffle(boolean shuffle)
Description copied from interface: Player
Set whether to shuffle the playlist

Specified by:
setShuffle in interface Player

setRepeat

public void setRepeat(int repeat)
Description copied from interface: Player
Set the style of repeat - none (0), track only (1) or playlist (2)

Specified by:
setRepeat in interface Player

getRepeat

public int getRepeat()
Description copied from interface: Player
Get the repeat mode, as set by Player.setRepeat(int)

Specified by:
getRepeat in interface Player

getShuffle

public boolean getShuffle()
Description copied from interface: Player
Get the shuffle mode, as set by Player.setShuffle(boolean)

Specified by:
getShuffle in interface Player

getCurrentTrackIndex

public int getCurrentTrackIndex()
Description copied from interface: Player
Return the index in the list of tracks returned from Player.getPlaylist() that is currently playing. If no track is playing return -1

Specified by:
getCurrentTrackIndex in interface Player

getCurrentTrack

public Track getCurrentTrack()
Return the currently playing Track, or null if no track is playing

Specified by:
getCurrentTrack in interface Player

setVolume

public void setVolume(int volume)
Description copied from interface: Player
Set the current volume

Specified by:
setVolume in interface Player
Parameters:
volume - the volume, between 0 and 100

getVolume

public int getVolume()
Description copied from interface: Player
Return the current volume

Specified by:
getVolume in interface Player
Returns:
the volume, between 0 and 100

getRevision

public int getRevision()
Description copied from interface: Player
Return the revision number. This should be increased every time the Player's state is updated.

Specified by:
getRevision in interface Player

getDisplayName

public java.lang.String getDisplayName()
Description copied from interface: Player
Return a nice name for this Player for display to the user

Specified by:
getDisplayName in interface Player

getPlaylist

public ManualPlaylist getPlaylist()
Return the Playlist

Specified by:
getPlaylist in interface Player

getAvailableSpeakers

public java.util.Collection<Speaker> getAvailableSpeakers()
Description copied from interface: Player
Get the collection of speakers that could be used by this Player and that aren't currently in use elsewhere.

Specified by:
getAvailableSpeakers in interface Player

addSpeaker

public void addSpeaker(Speaker speaker)
Description copied from interface: Player
Add a Speaker to the Player. Should only be called by Speaker.setPlayer(org.qtunes.player.Player).

Specified by:
addSpeaker in interface Player

removeSpeaker

public void removeSpeaker(Speaker speaker)
Description copied from interface: Player
Remove a Speaker to the Player. Should only be called by Speaker.setPlayer(org.qtunes.player.Player).

Specified by:
removeSpeaker in interface Player

getSpeakers

public java.util.Collection<Speaker> getSpeakers()
Description copied from interface: Player
Return the list of Speaker objects current in use by this Player

Specified by:
getSpeakers in interface Player

startService

public void startService(ServiceContext context)
Description copied from interface: Service
Start the Service

Specified by:
startService in interface Service
Parameters:
context - the ServiceContext for this Service

stopService

public void stopService(ServiceContext context)
Description copied from interface: Service
Stop the Service

Specified by:
stopService in interface Service
Parameters:
context - the ServiceContext for this Service (same as was passed into start)

getContext

public ServiceContext getContext()
Description copied from interface: Service
Return the ServiceContext that was passed into Service.startService(org.qtunes.core.ServiceContext)

Specified by:
getContext in interface Service

reportState

public java.util.Map<java.lang.String,java.lang.Object> reportState()
Description copied from interface: Service
Return a Map describing the state of this Service, for serialization back to any client that needs to know (eg webplayer) - so values should be serializable objects, eg Lists, Maps or simple objects. If no useful state, return null.

Specified by:
reportState in interface Service

handleEvent

public void handleEvent(java.lang.String name,
                        java.util.Map<?,?> properties)
Specified by:
handleEvent in interface Listener