sk.baka.ambient.collection.local
Class MediaStoreCollection

java.lang.Object
  extended by sk.baka.ambient.collection.local.MediaStoreCollection
All Implemented Interfaces:
ICollection

public final class MediaStoreCollection
extends Object
implements ICollection

Wrapper for Android MediaStore class.

Author:
Martin Vysny

Field Summary
(package private) static String[] TRACK_COLUMNS
          Columns used when retrieving tracks from MediaStore.
 
Constructor Summary
MediaStoreCollection(ContentResolver resolver)
          Creates new collection wrapper.
 
Method Summary
 CategoryItem deserializeItem(String serializedItem)
          Deserializes item serialized by ICollection.serializeItem(CategoryItem).
 List<TrackMetadataBean> findTracks(Map<CategoryEnum,String> criteria)
          Search for tracks using given criteria search.
 Map<String,String> fixLocations(Collection<String> locations)
           Given locations became invalid and need fixing.
 List<CategoryItem> getCategoryList(CategoryEnum request, CategoryItem context, String substring, boolean sortByYear)
          Returns category list matching given criteria.
 String getName()
          Returns short descriptive name of this collection backend.
 Statistics getStatistics()
          Returns statistics for this collection.
 List<TrackMetadataBean> getTracks(CategoryItem context)
          Returns all tracks contained in given category.
 boolean isLocal()
          Checks if the underlying strategy uses local resources to retrieve metadata (a DB backend), or it uses remote access to a server (for example Ampache).
 IDynamicPlaylistTrackProvider newTrackProvider(Random random)
          Returns a new instance of the track provider.
(package private) static TrackMetadataBean readTrack(Cursor c, Uri contentUri)
          Reads a single track from current cursor position.
(package private) static List<TrackMetadataBean> readTracks(Cursor c, Uri contentUri)
          Reads tracks from given cursor.
 List<TrackMetadataBean> searchTracks(String substring)
          Search song which Song Title, Artist Name, Album Name or Genre Name contains given substring.
 String serializeItem(CategoryItem item)
          Returns ID returned by this collection in the CategoryItem.id as String.
 boolean supportsLocationFix()
          Serves for optimalization purposes only: checks if this collection can perform obsolete locations fixup or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRACK_COLUMNS

static final String[] TRACK_COLUMNS
Columns used when retrieving tracks from MediaStore.

Constructor Detail

MediaStoreCollection

public MediaStoreCollection(ContentResolver resolver)
Creates new collection wrapper.

Parameters:
resolver - resolves URI. Must not be null.
Method Detail

deserializeItem

public CategoryItem deserializeItem(String serializedItem)
Description copied from interface: ICollection
Deserializes item serialized by ICollection.serializeItem(CategoryItem). This item will be used to perform search only. This functionality is only used by AmpacheServer. You do not need to store the CategoryItem.category - it will be overwritten.

Specified by:
deserializeItem in interface ICollection
Parameters:
serializedItem - the item to deserialize
Returns:
the ID instance.

getCategoryList

public List<CategoryItem> getCategoryList(CategoryEnum request,
                                          CategoryItem context,
                                          String substring,
                                          boolean sortByYear)
                                   throws CollectionException,
                                          InterruptedException
Description copied from interface: ICollection
Returns category list matching given criteria. Returns sorted list, either by name or by the year.

Specified by:
getCategoryList in interface ICollection
Parameters:
request - the category to search for. Must not be null.
context - search in context of this item. May be null - in this case all categories are returned.
substring - if not null then all category names must contain this substring.
sortByYear - if true then the result category list is sorted by year, then by name. If false then sorted only by name. Ignored when the request parameter is not an album.
Returns:
list of categories. Must not be null, may be empty.
Throws:
CollectionException - thrown when the collection fails to return items.
InterruptedException - when interrupted.

getName

public String getName()
Description copied from interface: ICollection
Returns short descriptive name of this collection backend.

Specified by:
getName in interface ICollection
Returns:
the name.

getStatistics

public Statistics getStatistics()
Description copied from interface: ICollection
Returns statistics for this collection.

Specified by:
getStatistics in interface ICollection
Returns:
the statistics object, must not be null.

getTracks

public List<TrackMetadataBean> getTracks(CategoryItem context)
                                  throws CollectionException,
                                         InterruptedException
Description copied from interface: ICollection
Returns all tracks contained in given category.

Specified by:
getTracks in interface ICollection
Parameters:
context - search in context of this item. Must not be null.
Returns:
list of tracks, sorted in no particular order. Must not be null, may be empty.
Throws:
CollectionException - thrown when the collection fails to return items.
InterruptedException - when interrupted.

readTracks

static List<TrackMetadataBean> readTracks(Cursor c,
                                          Uri contentUri)
                                   throws InterruptedException
Reads tracks from given cursor. The cursor must have columns as specified in TRACK_COLUMNS.

Parameters:
c - the cursor to poll. Closed when the method finishes.
contentUri - uses this URI when setting the location of retrieved tracks
Returns:
list of tracks.
Throws:
InterruptedException

readTrack

static TrackMetadataBean readTrack(Cursor c,
                                   Uri contentUri)
Reads a single track from current cursor position. The cursor must have columns as specified in TRACK_COLUMNS.

Parameters:
c - the cursor to poll. The cursor is not moved.
contentUri - uses this URI when setting the location of retrieved tracks
Returns:
the track

isLocal

public boolean isLocal()
Description copied from interface: ICollection
Checks if the underlying strategy uses local resources to retrieve metadata (a DB backend), or it uses remote access to a server (for example Ampache).

Specified by:
isLocal in interface ICollection
Returns:
true if the collection queries will tend to be performed fast, false otherwise.

searchTracks

public List<TrackMetadataBean> searchTracks(String substring)
                                     throws InterruptedException
Description copied from interface: ICollection
Search song which Song Title, Artist Name, Album Name or Genre Name contains given substring.

Specified by:
searchTracks in interface ICollection
Parameters:
substring - the substring to search for.
Returns:
the list of tracks. Must not be null, may be empty. Sorted in no particular order.
Throws:
InterruptedException - when interrupted.

serializeItem

public String serializeItem(CategoryItem item)
Description copied from interface: ICollection
Returns ID returned by this collection in the CategoryItem.id as String. This item will only be used to perform searches - you should thus preserve minimum information from the category item. This functionality is only used by AmpacheServer. You do not need to store the CategoryItem.category - it will be overwritten.

Specified by:
serializeItem in interface ICollection
Parameters:
item - the item to convert
Returns:
string representation of given item.

newTrackProvider

public IDynamicPlaylistTrackProvider newTrackProvider(Random random)
Description copied from interface: ICollection
Returns a new instance of the track provider. May return null if this collection does not provide this functionality. It is caller's responsibility to close the provider.

Specified by:
newTrackProvider in interface ICollection
Parameters:
random - initially provide tracks using this random value.
Returns:
new provider instance, may be null.

findTracks

public List<TrackMetadataBean> findTracks(Map<CategoryEnum,String> criteria)
                                   throws CollectionException,
                                          InterruptedException
Description copied from interface: ICollection
Search for tracks using given criteria search.

Specified by:
findTracks in interface ICollection
Parameters:
criteria - the criteria, must not be null. AND operator is used if multiple criteria are specified. String values are matched as substrings.
Returns:
tracks that comply given criteria, in no particular order.
Throws:
CollectionException - thrown when the collection fails to return items.
InterruptedException - when interrupted.

fixLocations

public Map<String,String> fixLocations(Collection<String> locations)
Description copied from interface: ICollection

Given locations became invalid and need fixing.

MediaPlayer detected an error while playing first location URL from given location list. All given locations might thus have become invalid. The collection is asked to fix these locations: it should re-connect to the server (if any) and/or perform any required steps. If any of these locations became completely invalid the method is free to omit them in the result map. If the collection is unable to fix given location then just pass input location.

Invoked asynchronously. This method will receive only locations provided earlier by track lookup methods such as ICollection.findTracks(Map).

Specified by:
fixLocations in interface ICollection
Parameters:
locations - the list of (possibly) invalid locations. Never null nor empty.
Returns:
a map of locations, maps original location to a fixed locations. Must not be null.

supportsLocationFix

public boolean supportsLocationFix()
Description copied from interface: ICollection
Serves for optimalization purposes only: checks if this collection can perform obsolete locations fixup or not.

Specified by:
supportsLocationFix in interface ICollection
Returns:
true if ICollection.fixLocations(Collection) is supported, false if the collection cannot fix the locations, or the fix operation is not applicable to this collection.


Copyright © 2007-2008. All Rights Reserved.