Results 1 to 19 of 19

Thread: [RESOLVED] Shuffle Function in MP3 player

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    61

    Resolved [RESOLVED] Shuffle Function in MP3 player

    I am tryin to impliment the shuffle function on my mp3 player. I've tried several methods and all with no luck including
    Code:
    WindowsMediaPlayer1.settings.setMode "shuffle", True
    This same method worked for me as a loop to repeat the current song. But isn't working with shuffle as i seen in some other posts. I am using WMP version 9, will this make a difference or is there a different way with version 9? (also the EndOfStream Event never occurs, I feel this may be one of the issues).
    Any help is greatly appreciated, Thanx.

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Shuffle Function in MP3 player



    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    61

    Re: Shuffle Function in MP3 player

    oh thanx bro. i didn't think anyone would respond since it was marked resolved.

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    61

    Re: Shuffle Function in MP3 player

    yea jmsrickland his source uses the same code that i mentioned didn't work with my version of wmp. I appreciate the response though. any other suggestions?

  5. #5
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    Re: Shuffle Function in MP3 player

    Quote Originally Posted by Future_FireFighter View Post
    any other suggestions?
    update WMP ?

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    61

    Re: Shuffle Function in MP3 player

    i'm usin wmp9. i thought that was the updated version. cuz i just updated it like a week ago?

  7. #7
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    Re: Shuffle Function in MP3 player

    im on media 11
    why not add the mp3 to a listbox and use something like . . . . .
    Code:
    Private Sub Command1_Click()
    Dim r As Integer
    Dim storeit As String
    r = List1.ListCount - 1
    List1.Visible = False
    For i = 0 To List1.ListCount - 1
        List1.ListIndex = i
        storeit = List1.Text
        List1.RemoveItem List1.ListIndex
        List1.AddItem storeit, Int(Rnd * r)
    Next i
    List1.ListIndex = 0
    List1.Visible = True
    End Sub
    
    Private Sub Form_Load()
    For n = 1 To 10
    List1.AddItem "mp3" & n
    Next
    End Sub

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    61

    Re: Shuffle Function in MP3 player

    My playlist is in a listbox, If i update to 11 would the code
    Code:
    WindowsMediaPlayer1.settings.setMode "shuffle", True
    work? If so i'll update to 11

  9. #9
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    Re: Shuffle Function in MP3 player

    take a look at this you might be better off switching to list to play your files
    Attached Files Attached Files

  10. #10

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    61

    Re: Shuffle Function in MP3 player

    I got this to work. I apologize I wasn't clear what I was lookin for. I wasn't looking for an actual shuffle event. But more of a play random song event in the playlist. I have the following code and it works. But it won't stop long enough to play the song. It keeps repeating the random without playing the song.

    Code:
    If chkShuffle.Value = vbChecked Then
            rand = Int(lstMusic.ListCount * Rnd)
            lstMusic.ListIndex = rand
        Call cmdPlay_Click
    End If
    I tried to fix it with this code. And it doesn't work at all.

    Code:
    If chkShuffle.Value = vbChecked Then
        If Player.playState = wmppsStopped Then
            rand = Int(lstMusic.ListCount * Rnd)
            lstMusic.ListIndex = rand
        Call cmdPlay_Click
    End If
    End If
    Any advice? Again the first code works exactly how i would like it to, I just need it to stop to play the song before it randomizes again. (This code doesn't change the order of the playlist, just chooses random song in the playlist). I hope this clears up some issues. Thanx for any help

  11. #11
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Shuffle Function in MP3 player

    Quote Originally Posted by Future_FireFighter View Post
    I got this to work. I apologize I wasn't clear what I was lookin for. I wasn't looking for an actual shuffle event. But more of a play random song event in the playlist. I have the following code and it works. But it won't stop long enough to play the song. It keeps repeating the random without playing the song.
    May I please use this in my media player?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  12. #12
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Shuffle Function in MP3 player

    Because of computer failure and moving to different machines, I don't know if I can find my experiments of using the current generation of Windows Media Player with VB6. I have one I wrote years ago that used the previous generation (the .ocx version) of WMP, which was simpler to use, but that isn't really applicable here.
    But, to sequence individual songs from my own list (rather than from a WMP playlist), the "trick" was not to try to test and change some actions in a WMP event itself.
    i.e, rather than get a WMP PlayStateChanged event (didn't look it up so don't know if that is a real event) and decide to issue a play request within that event, I would just set a flag indicating I want to issue a Play request, and allow the event handler sub to exit.
    A timer control is constantly cycling and will see the Play Request Flag, so it will issue the request.
    By only setting flags in the event handlers and processing the flags in the timer event, I think you avoid the situations where doing an WMP operation in an event handler will trigger another event which your code will go into and process without having exited the original event handler yet.
    That nesting of event processing I believe causes sequencing problems in your code logic, so things don't work in the sequential nature you intended.
    I wish I could readily lay my hands on that VB6 code to give you an example, but perhaps the description above may lead you to a solution yourself.

  13. #13
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    Re: Shuffle Function in MP3 player

    take a look at this example
    once yourve added all the files to list 1 and selected a track to play
    when the wmp stoped event is triggered at the end of track
    it checks if the box is checked
    and chooses random entry : )

    you could monitor the Current_Position of tracks they always end up back at 0
    but when you start playing a mp3 it starts at 0 so makes things more compicated i guess
    Attached Files Attached Files

  14. #14

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    61

    Re: Shuffle Function in MP3 player

    Sure thing NightWalker. Doesn't bother me at all. If you get it to work right let me know what you did differently though if you don't mind.

    I checked out that example you posted rattled and the random function didn't work at all. Sometimes it would just keep playing the same song and sometimes it would just move to the next song in the list.


    I'm sure putting this on the timer was a bad idea lol. I'll work with it tonight again.
    Last edited by Future_FireFighter; Oct 16th, 2014 at 02:39 PM.

  15. #15
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Shuffle Function in MP3 player

    I'm not sure now what part you don't have working.
    It sounded like you had the shuffle working, but it wouldn't play the selected song.
    You don't show exactly where you have the Random selection code.
    It should only be called once the selected song has been played. Is that the problem? You keep calling the code continuously to select new random songs without waiting for the song to startup and play?
    Perhaps you need a latch or state (like the playstate) so you note in the random selection that you've picked a song so the state will be set to playing.
    As long as the state is playing, you won't select another song.
    Once the song is finished start another.
    As I said in my case I started the other in the periodic timer event, so basically two bits of code, not counting the code that fetches the songs from the list (in order or in random order).
    Code:
    Private Sub MediaPlayer1_PlayStateChange(ByVal NewState As Long)
    'I had other states in the case, but aren't currently needed
        Select Case NewState
          Case wmppsMediaEnded
            DequeueASong = True
        End Select
    End Sub
    
    Private Sub Timer1_Timer()
      If DequeueASong Then
        DequeueASong = False
        Play_Next_Song   'Selects the next song and sets MediaPlayer1.URL to it
      End If
      
      DurPos = MediaPlayer1.currentMedia.duration
      Dur$ = TimeOf(DurPos)
      CurPos = MediaPlayer1.Controls.currentPosition
      Update_Time  'Show progress of the song playing as it plays
    End Sub
    p.s. The way I did my random playlist was with the desire of not repeating the songs, so I always use an array of indexes into my list of songs and the sequence number say 15 for example (15 of 876) always indexes into the index array to select the song by number.
    So, if Random is not selected the index array (1 to 876) is set to the numbers 1 to 876, so IndexList(15) = 15 so I play song 15.
    If Random is selected, then I shuffle the index array so now the numbers in the array are still 1 to 876 but in random order.
    Now I play entry 15, but entry 15 is some random song number IndexList(15) = ?(something from 1 to 876).
    So the sequencer just increments the number linearly (1 to 876) and wraps, and that sequence number picks the actual song index to be played from the IndexList array which is switched between linear or random at the users discretion.

    p.p.s I just went ahead and modified the old VB6 mediaplayer I wrote 11 years ago, or so, to use the newer (wmp.dll) Windows Media Player rather than the old (msdxm.ocx) Windows Media Player. Took about an hour and 1/2. The only player event I'm using is the PlayStateChanged so that only took a few minutes to update. Then it was mostly adding the extra layer on all the object methods and properties, e.g. MediaPlayer1.CurrentPosition to MediaPlayer.Controls.CurrentPosition. And the Volume works differently, so had to look that up and make some adjustments.
    Don't know if anyone would want to look at it. I wrote it and used it at my last job, but haven't used it in the last 7 years or so. And it isn't exactly intuitive, but it suited my needs at the time. I just wanted something that allowed me to drag and drop files on it to add them to the list, have the option to save where I am in the list whenever I shutdown, so will pickup playing the same song at the same point as when it shutdown. Also had an "Audition" button, so I could drag and drop songs on the button and it would add them to an audition list and switch to it, so I could listen to new songs AdHoc, but then return and pickup my main list where I left off. Just a fairly simple player that didn't do to much else.
    Last edited by passel; Oct 16th, 2014 at 06:58 PM.

  16. #16
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Shuffle Function in MP3 player

    This is how I did the next song part for my mini media player found here.

    Code:
    If frmMain.WMPMini.playState = wmppsStopped Then
        If s >= frmSetup.Lstsongs.ListCount Then
           s = 0
        Else
           s = s + 1
        End If
        play (s)
     End If
    Instead of

    Code:
    s = s + 1
    it would be something such as

    Code:
    s = s + Rnd(frmSetup.Lstsongs.ListCount -1)
    Edit:

    Code:
    If s >= frmSetup.Lstsongs.ListCount And frmMain.mnuShuffle.Checked = True Then
           s = 0
        Else
         s = s + Rnd(frmSetup.Lstsongs.ListCount - 1)
        End If
        play (s)
    End if
    That code work for shuffling the songs in the playlist.
    Last edited by Nightwalker83; Oct 16th, 2014 at 08:51 PM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  17. #17

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    61

    Re: Shuffle Function in MP3 player

    i'm not trying to shuffle the playlist though

  18. #18
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Shuffle Function in MP3 player

    Quote Originally Posted by Future_FireFighter View Post
    i'm not trying to shuffle the playlist though
    That is what it looks like to me from reading what you wrote in post #10.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  19. #19

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    61

    Re: Shuffle Function in MP3 player

    yea i'm sorry. I didn't change the name of the checkbox til just a few mins ago. I was trying to get it to choose a random song within the playlist without changing the list itself. Sorry for the misunderstanding. I got it working. I had the code in the wrong spot. It wasn't making it to the random function. I got it working now. Thanx passel. You gave me the idea that it was in the wrong place. but otherwise its working perfectly. Thanx everyone for all the help.

Posting Permissions

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



Click Here to Expand Forum to Full Width