Zooz

Hello,

I have an mp3 player that could play mp3s and playlists(premade from windows media player(it only conatins mp3s)). When i launch a playlist i need to keep pressing (next) button to get to the song i want. So, when i launch a playlist(*.wpl) i want it to be shown in a listbox or a treenode... whatever, but in a way that i could play and view the songs i have already put in it.

Anybody can help




Re: Visual Basic Language WMP Playlist viewing & playing

Bruno Yu - MSFT

Zooz,

Please try the following code:

Code Snippet

Public Sub weblist_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles weblist.SelectedIndexChanged

' Store the index of the selected item in the list box.

Dim lb As System.Windows.Forms.ListBox = sender

Dim index As Integer = lb.SelectedIndex

' Store the corresponding media item from the playlist.

Dim listItem As WMPLib.IWMPMedia = audioPlaylist.Item(index)

' Set the player URL to the URL of the selected media item.

player.URL = listItem.sourceURL

End Sub

Please take a look at the IWMPPlaylist.Item property in the following link:

http://msdn2.microsoft.com/en-us/library/bb249187.aspx






Re: Visual Basic Language WMP Playlist viewing & playing

Zooz

I have problems in ur code:

1- I didn't find any thing called weblist in components, and this leaded it to not working.

2- Audioplaylist: shall i write above it wmp.currentplaylist

3- i didnt understand it, will it show me the whole playing list

Thx anyway for trying to help






Re: Visual Basic Language WMP Playlist viewing & playing

nogChoco

Hi Zooz,

I think Bruno's example is code from the SelectedIndexChanged event of a playlist-listbox (named 'weblist' in the example). audioPlaylist is also some variable that's probably pointing to a playlist object. In short, the example is part from a bigger piece of code and Bruno posted a snippet from it to illustrate how to play an item from a playlist.

Here's a working example with a windows media player playlist:



Re: Visual Basic Language WMP Playlist viewing & playing

Tall Dude

NogChoco,

I liked your code, so hacked on it a little to see if I

could add 'wav' files at the same time.

(My changes probably can be simplified.)

Private Sub Update_The_Playlist()

' Load all the mp3 files that are in the selected folder (stored as full filepaths, example: "c:\myFolder\myFile.mp3")

zMP3Files = New List(Of String)(My.Computer.FileSystem.GetFiles(zMP3Folder, FileIO.SearchOption.SearchTopLevelOnly, "*.mp3"))

zMP3Files.AddRange(My.Computer.FileSystem.GetFiles(zMP3Folder, FileIO.SearchOption.SearchTopLevelOnly, "*.wav"))

' create a new empty playlist for the mediaplayer

zPlaylist = AxWindowsMediaPlayer1.playlistCollection.newPlaylist("thePlaylist")

' go through the list of mp3files and add them to the new playlist

For Each zFilePath As String In zMP3Files

If (System.IO.Path.GetExtension(zFilePath)).ToUpper = ".MP3" Then

Dim zMP3File As WMPLib.IWMPMedia3 = CType(AxWindowsMediaPlayer1.newMedia(zFilePath), WMPLib.IWMPMedia3)

zPlaylist.appendItem(zMP3File)

Else

Dim zMP3File As WMPLib.IWMPMedia = CType(AxWindowsMediaPlayer1.newMedia(zFilePath), WMPLib.IWMPMedia)

zPlaylist.appendItem(zMP3File)

End If

'Dim zMP3File As WMPLib.IWMPMedia3 = CType(AxWindowsMediaPlayer1.newMedia(zFilePath), WMPLib.IWMPMedia3)

'zPlaylist.appendItem(zMP3File)

Next






Re: Visual Basic Language WMP Playlist viewing & playing

nogChoco

Cool, Tall Dude

Just a note - the GetFiles lines can be merged like this:

zMP3Files = New List(Of String)(My.Computer.FileSystem.GetFiles(zMP3Folder, FileIO.SearchOption.SearchTopLevelOnly, New String() {"*.mp3", "*.wav"}))

Using the MediaPlayer's playlist is a bit of overkill as a listbox would be enough to keep track of the items, but I kept it in for "examplificational purposes" although it's probably not being used correctly (I couldn't make too much sense out of the MSDN docs).





Re: Visual Basic Language WMP Playlist viewing & playing

Tall Dude

Thanks nogChoco,

I'm picking up some good stuff here!

I never spend much time on the media player; but from my

internet searches, I couldn't make much sense of how to

get at some of those functions like 'playlist'.

You've made more sense of it than me!






Re: Visual Basic Language WMP Playlist viewing & playing

Zooz

Man you got me in the wrong way.

I have these already made windows media player playlists(*.wpl) which be automatically generated(from an already specified folder from my code) when my program starts, they will be shown in a context menu strip called(plcms). What you have done was to show me what are the mp3 files in a specified folder, what I want is to show the media already put in my already made playlists.

Thx anyway nogChoco for trying to help...


Hoping you'll help me with this.






Re: Visual Basic Language WMP Playlist viewing & playing

nogChoco

Hi again, Zooz, sorry about the misunderstanding

Here's a new working sample that loads *.wpl files from a given folder and displays them as playlist-menuitems with all the tracks as submenuitems. Rightclick the listbox to see the menu.




Re: Visual Basic Language WMP Playlist viewing & playing

Zooz

Thanks man your code worked very well, however, i didn't understand how did you enter to wmp playlist and listed the names.

Well thx anyway.






Re: Visual Basic Language WMP Playlist viewing & playing

nogChoco

The names are listed in the Listbox(=LB1) via this line:
LB1.Items.AddRange(zListOfTracks.ToArray)

Listbox.AddRange allows you to add multiple items to the listbox at the same time, and zListOfTracks (which is a List(Of String)) can easily be converted to an array of strings, which is what the AddRange method needs.

The WMP knows the list of tracks by setting the AxWMP1.currentPlaylist = zPlayList and then .currentItem is the way to select a track from that currentPlaylist.

The Playlist itself, is built by the
AxWMP1.newPlaylist() method which loads the playlist from a playlist-file.






Re: Visual Basic Language WMP Playlist viewing & playing

MazterzDemon

hey umm, It says "Path is not declared". in this sub

i know that both "Dim path as" , and "Dim getfilename as" are needed.

i just dont know what to put after As. any help

Private Sub CreatePlayListItems(ByVal zGivenFolder As String)

' Get all the playlists from the given folder

Dim zPlayListFiles As New List(Of String)(My.Computer.FileSystem.GetFiles(zGivenFolder, FileIO.SearchOption.SearchTopLevelOnly, New String() {"*.wpl", "*.pl", "*.m3u", "*.asx"}))

' Clear the contextmenustrip

Me.Init_CMS1()

Dim zPlayList As WMPLib.IWMPPlaylist

Dim zPlayListMenuItem As ToolStripMenuItem = Nothing

Dim zTrack As WMPLib.IWMPMedia3

Dim zTrackMenuItem As ToolStripMenuItem = Nothing

For Each zFilePath As String In zPlayListFiles

zPlayList = AxWindowsMediaPlayer1.newPlaylist(path.GetFileName(zFilePath), zFilePath)

zPlayListMenuItem = New ToolStripMenuItem(zPlayList.name, Nothing, AddressOf PlayListToolStripMenuItem_Click)

zPlayListMenuItem.Tag = zPlayList

zPlayListMenuItem.Owner = ContextMenuStrip1

I Bolded and underlined the part were it has the error.




Re: Visual Basic Language WMP Playlist viewing & playing

nogChoco

Hi MazterzDemon,

You can either add the Imports System.IO statement to the top of the code, or you can simply change the line to this one:

zPlayList = AxWindowsMediaPlayer1.newPlaylist(System.IO.Path.GetFileName(zFilePath), zFilePath)