sk.baka.ambient.collection.local
Class AbstractTrackProvider

java.lang.Object
  extended by sk.baka.ambient.collection.local.AbstractTrackProvider
All Implemented Interfaces:
Closeable, Serializable, Iterator<TrackMetadataBean>, IDynamicPlaylistTrackProvider
Direct Known Subclasses:
LibraryTrackProvider, MediaStoreTrackProvider

public abstract class AbstractTrackProvider
extends Object
implements IDynamicPlaylistTrackProvider

Provides random mix of tracks from the entire library.

Implementation note: this object causes a database Cursor to be opened for a long time - not probably a good strategy.

Author:
Martin Vysny
See Also:
Serialized Form

Constructor Summary
protected AbstractTrackProvider(Random random)
          Creates a new provider.
 
Method Summary
 void close()
           
protected abstract  List<TrackMetadataBean> getAlbumTracks(String album)
          Fetches all tracks for given album.
protected  Random getRandom()
          Returns current random value.
protected abstract  TrackMetadataBean getTrackFromCursor(Cursor c)
          Converts current row to a track bean.
 boolean hasNext()
           
protected abstract  Cursor newCursor(boolean albums)
          Creates new cursor, depending on the value of albums argument.
 TrackMetadataBean next()
           
 void remove()
           
 void removeFromHistory(int trackCount)
          Removes given amount of oldest tracks from the history.
 void reset()
          Reinitializes itself - polls tracks from the DB etc.
 void setRandom(Random random, TrackMetadataBean track)
          Sets the random mode of tracks provided next by the provider.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTrackProvider

protected AbstractTrackProvider(Random random)
Creates a new provider. Gets all files from the library.

Parameters:
random - The track ordering.
Method Detail

getRandom

protected final Random getRandom()
Returns current random value.

Returns:
the value of the playback order.

reset

public void reset()
Description copied from interface: IDynamicPlaylistTrackProvider
Reinitializes itself - polls tracks from the DB etc.

Specified by:
reset in interface IDynamicPlaylistTrackProvider

removeFromHistory

public void removeFromHistory(int trackCount)
Description copied from interface: IDynamicPlaylistTrackProvider
Removes given amount of oldest tracks from the history.

Specified by:
removeFromHistory in interface IDynamicPlaylistTrackProvider
Parameters:
trackCount - how many tracks to remove. If Integer.MAX_VALUE then entire history should be cleaned up.

setRandom

public void setRandom(Random random,
                      TrackMetadataBean track)
Description copied from interface: IDynamicPlaylistTrackProvider
Sets the random mode of tracks provided next by the provider. By default the Random.TRACK is set.

Specified by:
setRandom in interface IDynamicPlaylistTrackProvider
Parameters:
random - the random mode, never null.
track - optional current track. When Random.ALBUM, the provider should start providing an album starting with this track.

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<TrackMetadataBean>

next

public TrackMetadataBean next()
Specified by:
next in interface Iterator<TrackMetadataBean>

remove

public void remove()
Specified by:
remove in interface Iterator<TrackMetadataBean>

close

public void close()
Specified by:
close in interface Closeable

getAlbumTracks

protected abstract List<TrackMetadataBean> getAlbumTracks(String album)
Fetches all tracks for given album.

Parameters:
album - the album to fetch.
Returns:
track list, never null, may be empty if no such album exists. Not required to be sorted.

newCursor

protected abstract Cursor newCursor(boolean albums)
Creates new cursor, depending on the value of albums argument.

Parameters:
albums - if true then the cursor must provide string album names only, sorted by a random order. If false then the cursor must provide tracks sorted by random order.
Returns:
cursor, not null.

getTrackFromCursor

protected abstract TrackMetadataBean getTrackFromCursor(Cursor c)
Converts current row to a track bean. The cursor was provided by newCursor(boolean) invoked with false.

Parameters:
c - the cursor, never null, always on a valid line.
Returns:
non-null track instance.


Copyright © 2007-2008. All Rights Reserved.