Results 1 to 13 of 13

Thread: Program bypasses some code

Threaded View

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

    Re: Program bypasses some code

    As DataMiser says, you can add songs to a MediaPlayer PlayList and it will play the songs itself.

    <edit> I added the below before looking at your code and realizing that you are adding songs apparently to the playlist. I would assume you just need to start playing the first item and it should continue on automatically. If you want to read how I did it without using the builtin playlist you can continue reading
    </edit>
    <edit2>
    I see that the above edit was was DataMiser surmised as well in his post. I should have read a little further before posting.
    </edit2>

    But, as my VB6 code was originally written for the earlier version of MediaPlayer (around 15 years ago) which didn't have a playlist, I never got around to working with the built in playlist with the newer version of MediaPlayer (i.e. one available for the last 12 years or so). I maintained my own list and based on using the PlayStateChanged event to detect when a song was fininished and starting the next song.
    I'm now on the machine with more of my old VB6 code, so I'll take a look at what I did.
    Code:
      Const PLAYSTATE_Stopped = 1
      Const PLAYSTATE_Paused = 2
      Const PLAYSTATE_Playing = 3
      Const PLAYSTATE_MediaEnded = 8
    
      'added for new WMP
      Dim DequeueASong As Boolean
    
    
    Private Sub MediaPlayer1_PlayStateChange(ByVal NewState As Long)
    'I had other states in the case, but aren't currently needed
        Select Case NewState
          Case PLAYSTATE_MediaEnded
            DequeueASong = True
        End Select
    End Sub
    
    Private Sub Timer1_Timer()
      If DequeueASong Then
        DequeueASong = False
        Play_Next_Song
      End If
    End Sub
    The above is the crux of the code. The Call to sub Play_Next_Song is where I chose the next song to be played and loaded it. There was a lot of code in there using various indexes and calling other subs so I didn't bother posting it because it depends on a user defined type and other mechanisms that would just complicate things. You should be able to just keep track of which song you played from your list and start the next one.

    The reason it sets a flag in the PlayStateChange event and has code in the timer to start the next song is because starting a new song in the PlayStateChange event causes a PlayStateChange event and that seemed to corrupt the process somehow and the new song ended up not starting. Setting the flag and leaving the event, and then starting the song at the next timer tick, prevented that failure.

    p.s. The code has the comment "added for new WMP" referring to the boolean because the original Windows Media Player had a SongEnded event, and you could start a new song in that event without problem. The "new" WMP doesn't have the event any longer, or doesn't trigger it, and couldn't start a new song within the new event, so the boolean was added.
    Last edited by passel; Sep 22nd, 2017 at 10:59 AM.

Tags for this Thread

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