sk.baka.ambient.playlist
Class StaticPlaylistStrategy

java.lang.Object
  extended by sk.baka.ambient.playlist.StaticPlaylistStrategy
All Implemented Interfaces:
Serializable, IPlaylistStrategy

public final class StaticPlaylistStrategy
extends Object
implements IPlaylistStrategy, Serializable

A regular, old-school playlist. Manages the song ordering in playlist and queues. Supports shuffle and track repeat. Based on a 'static' list of tracks.

Author:
Martin Vysny
See Also:
Serialized Form

Constructor Summary
StaticPlaylistStrategy(IPlaylistStrategy strategy)
          Creates new static playlist strategy, optionally mimicking given strategy.
 
Method Summary
 void add(int i, List<TrackMetadataBean> tracks)
          Inserts given tracks before track with given index.
 void clearQueue()
          Clears queue from queued.
 void dequeue(int track)
          Dequeues given track if it was queued previously.
 int getCurrentlyPlaying()
          Returns currently playing track.
 List<PlaylistItem> getPlayItems()
           Returns list of playlist items.
 List<Integer> getQueue()
          Returns currently queued tracks.
 Random getRandom()
          Returns current random mode.
 Interval move(Interval interval, int target)
          Moves selected tracks before track with given index.
 Interval moveBy(Interval interval, int delta)
           Moves selected tracks up or down at least delta tracks, depending on the 'delta' value.
 int next()
          Moves to next track to be played.
 int peekNext()
          Peeks at the next track without actually changing the current track.
 int play(int track)
          Plays given track.
 int previous()
          Returns previous track to be played.
 void queue(Interval tracksToQueue)
          Queue this track for playing, after all other queued tracks.
 void reinit()
          Reinitializes the playlist - recomputes new random track ordering etc.
 void remove(Interval interval)
          Removes tracks with given index from the playlist.
 void replaceLocations(Map<String,String> locationMap)
          Modifies the playlist by changing all PlaylistItem locations.
 void setRandom(Random random)
          Sets the random mode.
 void shuffle()
          Randomize the playlist.
 int size()
          Returns the playlist length.
 void sortByAlbumOrder()
          Sorts the playlist with album order ordering.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StaticPlaylistStrategy

public StaticPlaylistStrategy(IPlaylistStrategy strategy)
Creates new static playlist strategy, optionally mimicking given strategy.

Parameters:
strategy - the strategy to mimic. If null then an empty playlist is created.
Method Detail

getCurrentlyPlaying

public int getCurrentlyPlaying()
Description copied from interface: IPlaylistStrategy
Returns currently playing track. Note that the playlist is not connected to the player and the player itself may be paused or stopped.

Specified by:
getCurrentlyPlaying in interface IPlaylistStrategy
Returns:
currently playing track or -1 if nothing is being played. Index to the IPlaylistStrategy.getPlayItems() list.

shuffle

public void shuffle()
Description copied from interface: IPlaylistStrategy
Randomize the playlist.

Specified by:
shuffle in interface IPlaylistStrategy

size

public int size()
Description copied from interface: IPlaylistStrategy
Returns the playlist length.

Specified by:
size in interface IPlaylistStrategy
Returns:
the playlist length.

sortByAlbumOrder

public void sortByAlbumOrder()
Description copied from interface: IPlaylistStrategy
Sorts the playlist with album order ordering.

Specified by:
sortByAlbumOrder in interface IPlaylistStrategy

getPlayItems

public List<PlaylistItem> getPlayItems()
Description copied from interface: IPlaylistStrategy

Returns list of playlist items. The operation must be quick - it should for example provide immutable view on an internal playlist structure, it should not recompute the list anew on each call.

Each PlaylistItem in the list must be an unique instance.

Specified by:
getPlayItems in interface IPlaylistStrategy
Returns:
list of playlist items, will not be modified.

clearQueue

public void clearQueue()
Description copied from interface: IPlaylistStrategy
Clears queue from queued.

Specified by:
clearQueue in interface IPlaylistStrategy

getQueue

public List<Integer> getQueue()
Description copied from interface: IPlaylistStrategy
Returns currently queued tracks.

Specified by:
getQueue in interface IPlaylistStrategy
Returns:
queued tracks, never null.

setRandom

public void setRandom(Random random)
Description copied from interface: IPlaylistStrategy
Sets the random mode. Currently played track must be preserved.

Specified by:
setRandom in interface IPlaylistStrategy
Parameters:
random - the random mode, never null.

remove

public void remove(Interval interval)
Description copied from interface: IPlaylistStrategy
Removes tracks with given index from the playlist. If currently played track is removed then the current song must be set to -1.

Specified by:
remove in interface IPlaylistStrategy
Parameters:
interval - the interval to remove

add

public void add(int i,
                List<TrackMetadataBean> tracks)
Description copied from interface: IPlaylistStrategy
Inserts given tracks before track with given index.

Specified by:
add in interface IPlaylistStrategy
Parameters:
i - the index, must not be negative.
tracks - the tracks meta, must not be null.

dequeue

public void dequeue(int track)
Description copied from interface: IPlaylistStrategy
Dequeues given track if it was queued previously. Does nothing if the track is not present in the queue anymore.

Specified by:
dequeue in interface IPlaylistStrategy
Parameters:
track - the track to dequeue.

queue

public void queue(Interval tracksToQueue)
Description copied from interface: IPlaylistStrategy
Queue this track for playing, after all other queued tracks. Does nothing if the track is already queued.

Specified by:
queue in interface IPlaylistStrategy
Parameters:
tracksToQueue - the tracks to queue, index to the IPlaylistStrategy.getPlayItems() list.

reinit

public void reinit()
Description copied from interface: IPlaylistStrategy
Reinitializes the playlist - recomputes new random track ordering etc. Removes all queued tracks and stops the playback (IPlaylistStrategy.getCurrentlyPlaying() will return -1).

Specified by:
reinit in interface IPlaylistStrategy

peekNext

public int peekNext()
Description copied from interface: IPlaylistStrategy
Peeks at the next track without actually changing the current track.

Specified by:
peekNext in interface IPlaylistStrategy
Returns:
next track index. Returns -1 when there's no track left. Dynamic playlist may return -1 when there are no upcoming tracks and the queue is empty.

next

public int next()
Description copied from interface: IPlaylistStrategy
Moves to next track to be played. Returns -1 if no more tracks are to be played - this also causes the IPlaylistStrategy.getCurrentlyPlaying() method to return -1. Calling this method while not playing anything will start to play first track.

Specified by:
next in interface IPlaylistStrategy
Returns:
play item to play next or -1 if no more items are to be played. Index to the IPlaylistStrategy.getPlayItems() list.

play

public int play(int track)
Description copied from interface: IPlaylistStrategy
Plays given track. The playback continues from this track forward, unless random play is activated.

Specified by:
play in interface IPlaylistStrategy
Parameters:
track - the track to play. Index to the IPlaylistStrategy.getPlayItems() list. If -1 then the current track pointer is moved before first track and the playback is stopped.
Returns:
the track that is being played.

previous

public int previous()
Description copied from interface: IPlaylistStrategy
Returns previous track to be played. Returns -1 if we are at the beginning of the playing track sequence. Calling this method while not playing anything will start to play last track.

Specified by:
previous in interface IPlaylistStrategy
Returns:
which item was played prior current track or -1 if we are at the beginning of the playing track sequence.

getRandom

public Random getRandom()
Description copied from interface: IPlaylistStrategy
Returns current random mode.

Specified by:
getRandom in interface IPlaylistStrategy
Returns:
the random mode, never null.

move

public Interval move(Interval interval,
                     int target)
Description copied from interface: IPlaylistStrategy
Moves selected tracks before track with given index. Correctly updates queue indices. Currently played track will not be changed, although the track index may change.

Specified by:
move in interface IPlaylistStrategy
Parameters:
interval - the interval to move
target - move tracks before track with this index. If this index is contained in the interval then nothing is done.
Returns:
a new interval which contains all moved tracks.

moveBy

public Interval moveBy(Interval interval,
                       int delta)
Description copied from interface: IPlaylistStrategy

Moves selected tracks up or down at least delta tracks, depending on the 'delta' value. The playlist may decide to move tracks by more tracks than requested - for example, the dynamic playlist will skip the currently playing/queued tracks. If the move is not possible (for example there are not enough tracks) then move the tracks to the beginning (or end) of the playlist.

Currently played track will not be changed, although the queue indices. Currently played track will not be changed, although the track index may change.

Specified by:
moveBy in interface IPlaylistStrategy
Parameters:
interval - the interval to move
delta - move tracks up 'delta' tracks (if delta is negative), or down 'delta' tracks (if delta is positive). Do nothing if delta is zero.
Returns:
a new interval which contains all moved tracks.

replaceLocations

public void replaceLocations(Map<String,String> locationMap)
Description copied from interface: IPlaylistStrategy
Modifies the playlist by changing all PlaylistItem locations.

Specified by:
replaceLocations in interface IPlaylistStrategy
Parameters:
locationMap - maps old locations to new locations.


Copyright © 2007-2008. All Rights Reserved.