Hi everyone. I am making a random music player. How can I play music randomly? My WMP(windows music Player) is Invisible in order to become a background music. What code should need to aplpy to create this program?
Here is my Code:

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AxWindowsMediaPlayer1.URL = ("Beyonce - Diva.mp3")  ' I want thi player to play randomly

        ENd Sub

Edited by gujinni: Lack of information

4 Years
Discussion Span
Last Post by G_Waddell

I've never worked with the Windows Music player before so here is a high level view of what I would do.
You will need to store the tracks listing either in a file or database unless you can access directly from the player.

Take a count of the track you have availble and use the random class to randomly pick a track.. something like this:

Private Function RandomTrackPicker(MaxValue as Integer, _
    Optional ByVal MinNumber As Integer = 0) As Integer

      'initialize random number generator
        Dim r As New Random(System.DateTime.Now.Millisecond)

      'if passed incorrect arguments, swap them
        'can also throw exception or return 0

        If MinNumber > MaxNumber Then
            Dim t As Integer = MinNumber
            MinNumber = MaxNumber
            MaxNumber = t
        End If

        Return r.Next(MinNumber, MaxNumber)

    End Function

Then whatever number returns should be a random number of a track to play.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.