Programming guides for beginner...
Any comments are welcomed....
I hope it helps!!! Thanks for drop by...

Tuesday, February 8, 2011

My first step-by-step tutorial on Simple Music Player (VS2008) Part III

 

     Continue from my previous post of Part I & Part II, this will be the last part of Simple Music Player. When you completed this part, you will be able to use the Music Player to play songs.

     The following coding in the “Check next songs” region is a function that used to check for next songs when current songs finish played. It also stops play when the playlist reached the end. The region for “timer start” is a function when a timer start ticking. The coding can also be approach by double click on timer1 that being added to the interface in Part I.

31

Your code should look like the above picture.

#Region "Check next songs"
    Private Sub Check_Next_Media()
        If int_currplayindex >= ListView1.Items.Count - 1 Then
            Timer1.Stop()
            objAudio.Stop()
            Button1.Text = "Play"
            b_musicEnding = True
            b_musicplaying = False
            Exit Sub
        End If
        b_musicEnding = False
        int_currplayindex += 1
        str_filepath = CStr(ListView2.Items.Item(int_currplayindex).Text)
        objAudio = New Audio(str_filepath, False)
        objAudio.Play()
    End Sub
#End Region

#Region "timer start"
    Private Sub Timer1_Tick(ByVal sender As System.Object, _
                            ByVal e As System.EventArgs) _
                            Handles Timer1.Tick
        ListView1.Items.Item(int_currplayindex).BackColor = Color.Blue
        'change the color here to show current playing music.
        If objAudio.CurrentPosition = objAudio.Duration Then
            b_musicEnding = True
        Else
            b_musicEnding = False
        End If
        If b_musicEnding = True Then
            ListView1.Items.Item(int_currplayindex).BackColor = clr_previous 'previous color
            Check_Next_Media()
        End If
    End Sub
#End Region

     After the the previous Part I & Part II, and also the above coding, you should be able to test your Player now. Press F5 to run the program. Now, you might faced a problem as shown in the picture below:


14



To solve this problem, you will need to change the exception.  Look for Debug | Exceptions. In Exceptions dialog, look for loaderlock in Managed Debugging Assistants and uncheck it at Thrown as shown in the picture below.


15


After that, you should have a working Music Player. If there is still problems, please feel free to leave a comment. I will try my best to help. Open-mouthed smile

No comments:

Post a Comment