By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Play Multiple Songs Using <Audio> Control


New member
Jul 26, 2016
The following code loads songs from the "Songs" folder into a listbox. I can click on any of the songs in the listbox, which loads the song into an <AUDIO> control. I can click play on the Audio control to play the song.

<script language="vbscript" runat="server">

    Public SongToPlay As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then ' First time ASPX page is loaded.
            SongToPlay = "Songs/Song1.mp3"
            Dim pathLocal As String
            Dim pathSongs As String
            ' Get current path
            pathLocal = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ServerVariables("PATH"))
            pathSongs = pathLocal & "\Songs"
            Dim MyFile, MyPath As String
            MyPath = pathSongs   ' Set Folder location for songs
            MyFile = Dir(pathSongs & "\*.mp3")
            Do While MyFile <> ""   ' Start the loop.
                ' Use bitwise comparison to make sure MyName is a directory.
                MyFile = Dir()   ' Get next entry.

            lbAllSongs.SelectedIndex = 0 ' Sets first song as default 
            lblSelectedSong.Text = lbAllSongs.SelectedItem.Text
            SongToPlay = "Songs/" & lbAllSongs.SelectedItem.Text
        End If '  If Not IsPostBack
    End Sub ' Page_Load


However, I would like it to play through the list of songs in the listbox without me having to click on each individual song.

I am trying to call a VB subroutine from within the <AUDIO> tag using the onended event. Here's the code:

 <audio id="audioPlayer" src="<%=SongToPlay %>" controls="true" onended="audioPlayerOnEnded()"></audio>

For some reason, it's not recognizing the subroutine that I'm calling. The onended has to be a Javascript routine, but I'm trying to call a VBScript from with Javascript.

If I can get the onended event to work, I could figure out a routine to play the next song without having to manually click an item in the listbox.

If this doesn't work, anyone have suggestions to play multiple songs using the <AUDIO> control?

Thanks in advance for the help.

Poppa Mintin

New member
Mar 5, 2009
Here are a couple of suggestions:
            If ListBox1.Items.Count > 0 then
                track = ListBox1.Items(0)

	'Put your playing code in here, or the Subroutine to play it for you.

            End If.

            For i = 0 to ListBox1.Items.Count - 1
                track = ListBox1.Items(i)

	'Put your playing code in here, or the Subroutine to play it for you.



PS. Are you sure you're in the correct forum ? This is for VB.NET.

Last edited: