Introduction
A much more simple way to create and manage Playlists for COM Media Player Objects such as Window Media Player.
Background
When I first attempted doing some Tutorials some time ago, One of the ones I was most excited to attempt the Windows Media Player Tutorial. I was annoyed at the difficultly to make a Playlist or Media Library to use with it. About a month or so ago I came up with this solution and forgot about it, then about a week ago while cleaning out my computer I came across the Source Code for this. So here it is.
Using the code
Here's the code to use to create the Playlist control.
//
Imports Microsoft.VisualBasic.FileIO.FileSystem
Public Class MainControl
Property MediaFolderPath As String = Nothing
Property SupportedExtentions As List(Of String)
Property MediaFiles As List(Of String)
Property MediaFileNames As List(Of String)
Property SelectedMediaFilePath As String = Nothing
Property SelectedMediaFriendlyName As String = Nothing
Enum ListMode As Integer
FileMode = 0
NameMode = 1
End Enum
Public Sub Init(Optional ByVal FetchNames As Boolean = False)
Try
MediaFiles = New List(Of String)
If IsNothing(SupportedExtentions) = False Then
If FileIO.FileSystem.DirectoryExists(MediaFolderPath) = True Then
For Each file As String In GetFiles(MediaFolderPath, FileIO.SearchOption.SearchAllSubDirectories)
For Each Extention As String In SupportedExtentions
If file.EndsWith(Extention) = True Then
MediaFiles.Add(file)
Exit For
End If
Next
Next
End If
End If
If FetchNames = True Then
FetchMediaNames()
End If
Catch ex As Exception
End Try
End Sub
Public Sub FetchMediaNames()
If IsNothing(MediaFiles) = False Then
MediaFileNames = New List(Of String)
For Each MediaItem As String In MediaFiles
Dim FriendlyName As String = GetFileInfo(MediaItem).Name.Replace(GetFileInfo(MediaItem).Extension, "")
MediaFileNames.Add(FriendlyName)
Next
End If
End Sub
Public Sub PopulateList(ListForUse As ListMode)
If ListForUse = ListMode.FileMode Then
For Each item As String In MediaFiles
PlayistView.Items.Add(item)
Next
ElseIf ListForUse = ListMode.NameMode Then
For Each friendlyname As String In MediaFileNames
PlayistView.Items.Add(friendlyname)
Next
End If
End Sub
Private Sub PlayistView_DoubleClick(sender As Object, e As EventArgs) Handles PlayistView.DoubleClick
If IsNothing(PlayistView) = False Then
SelectedMediaFilePath = MediaFiles(PlayistView.SelectedIndex)
SelectedMediaFriendlyName = GetFileInfo(MediaFiles(PlayistView.SelectedIndex)).Name.Replace(GetFileInfo(MediaFiles(PlayistView.SelectedIndex)).Extension, "")
End If
End Sub
End Class
//