Friday, October 28, 2011

Useful methods for getting track infos from banshee music library

Since I spent quite some time wondering how to do this, I decided to write down how you can get TrackInfos for certain TrackIds from banshee.

First you need banshee's DatabaseTrackModelProvider which can be found in Banshee.Collection.Database. One way of accessing the DatabaseTrackModelProvider<DatabaseTrackInfo> is using the static attribute Provider in DatabaseTrackInfo.
With this provider it is possible to get the TrackInfo for a track with a certain id using the following code:

TrackInfo ti = DatabaseTrackInfo.Provider.FetchSingle (bid) as TrackInfo; 

with bid being the ID used by banshee. In other words bid equals DatabaseTrackInfo.Provider.FetchSingle (bid).TrackId.

The provider can also be used for iterating over all tracks in banshee's database.

foreach (DatabaseTrackInfo dti in DatabaseTrackInfo.Provider.FetchAll ()) {
    // do something with dti
}

No comments:

Post a Comment