How to play the play list in vlc player by using vb.net code

Dani AI

Generated

If your goal is to play a whole XSPF playlist, VLC does support XSPF natively; the key is that the ActiveX control expects a valid MRL (media resource locator) such as a file URI (file:///C:/...) rather than a raw Windows path. That is why simply adding a filename may only play a single item. Convert Windows paths to file URIs, or hand the .xspf to VLC and let it expand the playlist. See VLC’s XSPF notes, the playlist API for playlist.add(mrl, name, options), and the MRL format. XSPF on VideoLAN, Playlist object methods, Media resource locator.

Two reliable approaches:

  • Shell out to VLC with the .xspf. This aligns with ’s suggestion to launch VLC, but gives you control over playback behavior.
Dim xspf As String = "C:\playlists\mylist.xspf"
Dim psi As New ProcessStartInfo With {
    .FileName = "C:\Program Files\VideoLAN\VLC\vlc.exe",
    .Arguments = """" & xspf & """ --playlist-autostart --one-instance --playlist-enqueue",
    .UseShellExecute = False
}
Process.Start(psi)

The options above autostart the list, reuse a running instance, and enqueue rather than interrupt current playback. Adjust as needed. VLC command-line help.

  • Expand the XSPF yourself, then enqueue each track into the control. This avoids version quirks where a nested playlist is not expanded by the control:
Imports System.Xml.Linq

Sub EnqueueXspf(ax As AxAXVLC.AxVLCPlugin2, xspfPath As String)
    Dim ns As XNamespace = "http://xspf.org/ns/0/"
    Dim doc = XDocument.Load(xspfPath)
    Dim baseDir = IO.Path.GetDirectoryName(xspfPath)

    For Each locElem In doc.Root.Element(ns + "trackList").
                           Elements(ns + "track").Elements(ns + "location")
        Dim s = locElem.Value.Trim()
        Dim mrl = If(Uri.IsWellFormedUriString(s, UriKind.Absolute),
                     s,
                     New Uri(IO.Path.GetFullPath(IO.Path.Combine(baseDir, s))).AbsoluteUri)
        ax.playlist.add(mrl)
    Next

    ax.play() ' start playback
End Sub

Note: New Uri(path).AbsoluteUri gives you the correct file:///... MRL that VLC expects. System.Uri class.

Recommended Answers

All 13 Replies

hmmmm, not sure what you're after. if your looking to call vlc istelf and pass the playlist, this is a simple shellexecute using the windows api, look at my answer in this post. It has a very nice sample in doing just that.

Thanq for the quick reply.
i Know how to open the file,i want to play the playlist (.XSPF) files in vlc player by using vb.net code.

I think just click on the options button of the playlist not so sure name but quite sure that was a 2nd last tab click on the tab there opio0n avaialable of playlist, click and past songs there which you want to play.

As long as the file is associated with VLC opening the file will use VLC to open it. Depending on the setting in VLC it should start playing.

With AxVLCPlugin21
            .CtlVisible = True
            .playlist.items.clear()
             .playlist.add(OpenFileDialog1.FileName)
            .playlist.play()
            .Toolbar = True
            .Show()
        End With

in the above code playing single song possible but i wont to play playlist by using the vb.net code.pls give suggestion how to play

According to members that show up in intellisense you should be able to do something like this:

For I= 0 to axvlcplugin21.playlist.items.count-1
    axvclplugin21.playlist.playitem(I)
next
With AxVLCPlugin21
.CtlVisible = True
.playlist.items.clear()
.playlist.add(OpenFileDialog1.FileName)
.playlist.play()
.Toolbar = True
.Show()
End With

.playlist.add(OpenFileDialog1.FileName)

in the above line adding only single file how to add multiple files

It looks to me that you just need to insert another .playlist.add() statement

How to play the play list that is .xspf formate its possible or not pls give a suggestion how to play

Use a loop to add multiple files:

    With AxVLCPlugin21
    .CtlVisible = True
    .playlist.items.clear()

    ' Loop until user presses Cancel button and
    ' add files to the playlist. The code _does not_ check the type of the file!
    Do Until OpenFileDialog1.ShowDialog() <> Windows.Forms.DialogResult.OK
       .playlist.add(OpenFileDialog1.FileName)
    Loop

    .playlist.play()
    .Toolbar = True
    .Show()
    End With

(Sorry about missing syntax coloring. I still haven't found how to do it!!!)
(Never mind :) It seems to come by itself...)

In above code also not working to play playlist(.xspf) file.

If its possible to play the play list(.xspf formate)in vlc by using vb.net code.If Yes, how?

you can try

 Dim strFilename As String
strFilename = Movies.PC_adresTextBox.Text
 AxVLCPlugin21.playlist.add("file:///" & strFilename)
 AxVLCPlugin21.playlist.play()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.