Friday, April 29, 2011

Accessing the music library using the Banshee API

Since it is not so obvious which classes can be used to access the meta data of the files in banshee's music library, here is an example of how it can be done using ServiceManager.SourceManager.MusicLibrary.TrackModel.

private string GetMetaData(int index) {
    return ServiceManager.SourceManager.MusicLibrary.TrackModel[index].ArtistName + " - " +
    ServiceManager.SourceManager.MusicLibrary.TrackModel[index].TrackTitle + " (" +
    ServiceManager.SourceManager.MusicLibrary.TrackModel[index].AlbumTitle + ")";
}

Calling this method within a loop over all TrackModels in the MusicLibrary and outputting it to the log

for (int i = 0; i < ServiceManager.SourceManager.MusicLibrary.TrackModel.Count; i++) {
    Hyena.Log.Debug(GetMetaData(i));
} 

generates output similar to this:

Muse - Exo-Politics (Black Holes and Revelations)

No comments:

Post a Comment