medialibrary

fsMediaLibrary.NET

C#/VB.NET 2.0 & 4.0 Library

Introduction

fsMediaLibrary is a .NET library designed to save time developing a Media Player or any application that requires the storage of Audio files, Playlist and Track information including cover artwork and Lyrics.

Having looked at the .NET component market place, there seems to be no library of this kind available and we believe there is a market for a component like this.

fsMediaLibrary comes installed in 2 versions (.NET 2.0/4.0) and compiled with ANYCPU.  Sample projects included have been created with VB.NET/C# 2008/2010.

There are 2 help files with this product.  This one and component API documentation.  This document will be updated as we get questions that need explaining.

The trial version of the library will expire in 30 days.

Features

  • Super fast binary database.
  • Automatically creates Metadata and Artwork databases.
  • Audio files are imported and stored within the database path location.  Progress events are available (see sample application included).
  • Add and Remove playlists.
  • Add and Remove tracks from playlists.
  • Add/Edit track details.
  • Set track rating.
  • Set/remove track artwork.
  • Set/remove track lyrics.
  • Use any tag library to obtain meta data from audio file (tag-sharp included in bin folder).
  • Export files from library to a folder.
  • Export album artwork to a folder
  • Lifetime support and upgrades.
  • Simple, easy and a quick way to build your media player.  MediaLibrary does the database part for you 🙂
  • Included same projects provide all the code you need to get going.

To connect to the library, please follow the steps here.

The first thing we need to do is to let MediaLibrary know where the folder is located that will be used to store the databases and music files.

We set the path using the following command:

MediaLibCore.Setup.SetLibraryPath(strPath)

This will cause MediaLibrary to check for the existence of databases in the destination path and if not found, will create them. If you have purchased a license key then you can disable the pop-up message by entering the key using the command below. You can purchase a license key by visiting our web site Fitzsoft.dev or see “Purchase a license and download”.

MediaLibCore.Setup.SetLicence(strRegisteredName, strPurchasedLicenseKey)

You can check to see if the license was validated ok with this code.

If MediaLibCore.Setup.isLicensed = False Then MsgBox(“MediaLib is not licensed. Please purchase a license key to unlock. Running in demo mode.”)  

The following code will add media files to the library.   See sample programs on how it all works in detail.  Here we use a listbox to log events.  MediaLibDemo.objlibFileImporter performs the main import function.

Dim importer As New MediaLibDemo.objLibFileImporter(_objLib, New List(Of String)(_filenames), False)

AddHandler importer.ProgressErrorEvent, AddressOf Importer_ProgressErrorEvent

AddHandler importer.ProgressEvent, AddressOf Importer_ProgressEvent

AddHandler importer.Completed, AddressOf Importer_Completed

importer.PerformCopy()

Events will fire for each event during the import process.

Private Sub UpdateListBox(ByVal message As String)

‘ message will contain information you can process or view

listBox1.Items.Add(message)

End Sub

Private Sub Importer_Completed(ByVal message As String)

If InvokeRequired Then

Me.Invoke(System.Delegate.CreateDelegate(GetType(DoUpdateListBox), Me, “UpdateListBox”), New Object() {message})

Else

‘ It is on main UI thread, so you can update the UI’

UpdateListBox(message)

End If

End Sub

Private Sub Importer_ProgressEvent(ByVal message As String)

If InvokeRequired Then

Me.Invoke(System.Delegate.CreateDelegate(GetType(DoUpdateListBox), Me, “UpdateListBox”), New Object() {message})

Else

‘ It is on main UI thread, so you can update the UI’

UpdateListBox(message)

End If

Application.DoEvents()

End Sub

Private Sub Importer_ProgressErrorEvent(ByVal message As String, _

ByVal errorMessage As String)

If InvokeRequired Then

Me.Invoke(System.Delegate.CreateDelegate(GetType(DoUpdateListBox), Me, “UpdateListBox”), New Object() {message})

Else

‘ It is on main UI thread, so you can update the UI’

UpdateListBox(message)

End If

Application.DoEvents()

End Sub

MediaLibDemo.objlibFileImporter class performs the import so please look at the project sample. Here is an example.

taglib-sharp.dll is used to read the media file metadata.

Dim mediaFile As TagLib.File = TagLib.File.Create(filename)

Dim newTrack As New MediaLibCore.AddTrack() ‘ Get track object and set parms

newTrack.FilePath = filename

newTrack.Album = mediaFile.Tag.Album

newTrack.Artist = mediaFile.Tag.FirstPerformer

newTrack.Bitrate = CUInt(mediaFile.Properties.AudioBitrate)

newTrack.Genre = mediaFile.Tag.FirstGenre

newTrack.Length = CUInt(mediaFile.Properties.Duration.TotalMilliseconds)

newTrack.TrackNumber = mediaFile.Tag.Track

……

newTrack.ArtworkFile = artworkFile ‘ Get path to artwork image on disk

……

So we have built the new track object, got the location on disk and added a reference to the artwork file (album cover)

If we track already exists in the library, it will error and return the track object so you can then use it to add to a playlist if you wish.

Dim addedTrack As MediaLibCore.Functions.LibraryDb.Track = Nothing

Try

addedTrack = _MediaLibrary.Tracks.Add(newTrack)

Catch ex As MediaLibCore.Exceptions.ErrTrackAlreadyExistsException

addedTrack = ex.ExistingTrack

End Try

To add a new playlist to the library, use the following.

Dim addedPlaylist As MediaLibCore.Functions.LibraryDb.Playlist = _MediaLibrary.Playlists.Add(“name”)

If the playlist is created then addedPlaylist variable will contain the newly created object.  You can then use that object to add tracks.

To add tracks to the playlist, either create the playlist or select an existing one.  Once you have the playlist object you can add tracks.

So we first connect to the playlist.

Dim ThisPlaylist As MediaLibCore.Functions.LibraryDb.Playlist = _MediaLibrary.Playlists.Add(“name”)

Now we have the playlist, we can add a track.

Dim thisTrack As MediaLibCore.Functions.LibraryDb.Track = trackobject ‘ trackobject is an exiting track.  See dragdrop code in playlistbox in sample project.

ThisPlaylist.AddTrack(thisTrack)

To copy all tracks from one playlist to another the following code with work.

For Each thisTrack As MediaLibCore.Functions.LibraryDb.Track In _MediaLibrary.Tracks

ThisPlaylist.AddTrack(thisTrack)

Next

Adding artwork to the track can be done by calling the SetArtwork function on the track.

Here we will add artwork to all tracks from album “Test”.

For Each trk As MediaLibCore.Functions.LibraryDb.TrackIn_MediaLibrary.Tracks

If trk.Album = “Test” Then

trk.SetArtwork(“image1.png”)

End If

Next

Want to become an Affiliate? Want to make up to 40% selling MediaLibrary?

Sign up today to become an affiliate and start selling MediaLibrary today.  All sales are handled through MyCommerce and you can earn up to 40%.

Click here for free signup and start earning today.