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

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.

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.