Click here to Skip to main content
Click here to Skip to main content

Tagged as

Creating a Playlist Control

, 27 Oct 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Resuable Playlist Control for Use with COM Media Player Objects Such as Window Media Player

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

//  

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

MattSparks

United States United States
No Biography provided

Comments and Discussions

 
GeneralMy vote of 1 PinmvpManfred R. Bihy31-Oct-12 6:09 
GeneralRe: My vote of 1 Pinmemberrspercy653-Nov-12 17:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141216.1 | Last Updated 27 Oct 2012
Article Copyright 2012 by MattSparks
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid