dcsimg
Results 1 to 2 of 2

Thread: Play Multiple Songs Using <Audio> Control

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2016
    Posts
    33

    Play Multiple Songs Using <Audio> Control

    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.

    Code:
    <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.
                    lbAllSongs.Items.Add(MyFile)
                    MyFile = Dir()   ' Get next entry.
                Loop
    
                lbAllSongs.SelectedIndex = 0 ' Sets first song as default 
                
            Else
                
                lblSelectedSong.Text = lbAllSongs.SelectedItem.Text
                SongToPlay = "Songs/" & lbAllSongs.SelectedItem.Text
            
            End If '  If Not IsPostBack
            
        End Sub ' Page_Load
    
    </script>
    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:

    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.

  2. #2
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,814

    Re: Play Multiple Songs Using <Audio> Control

    Here are a couple of suggestions:
    Code:
                If ListBox1.Items.Count > 0 then
                    track = ListBox1.Items(0)
                    ListBox1.Items.RemoveAt(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.
    
                Next

    Poppa.


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

    Pop.
    Last edited by Poppa Mintin; Feb 21st, 2020 at 07:09 PM. Reason: PS added
    Along with the sunshine there has to be a little rain sometime.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width