1

Here is a code snippet I cannot get to work. What I am trying to do is get windows media player to play an avi and when it is finished playing, I then want windows media player to turn "invisible" until the next time it needs to play an AVI.

   If brodyfile = 1 Then 'check character in file and play correct video.

       WindowsMediaPlayer1.URL = (App.Path & "\brody1.avi") 'play video

This line below doesn't work. How do I wait for windows media player to finish playing an avi before it becomes invisible ?

       While WindowsMediaPlayer1.playState = wmppsPlaying ' This line never works

       Sleep (500)

       Wend

       WindowsMediaPlayer1.uiMode = "invisible" ' This happens before AVI finishes playing.

   Endif
snoopen
  • 225
  • 1
  • 9
captainx
  • 25
  • 7

1 Answers1

1

The reason that isn't working is because it takes a short time for the video to start playing. When it gets to your while statement the video hasn't started playing so it's PlayState won't be wmppsPlaying.

You shouldn't use a Sleep either as it blocks the update of the UI. It's better to use a timer control.

This is what I would suggest. The timer checks the state every second but also doesn't do the first check for a second so the video should have time to start. If the video is loaded from a source that take a long time to load you might have to create a timer that checks for the video to start playing then another to check for it to stop.

Private Sub Command1_Click()
    Me.WindowsMediaPlayer1.URL = (App.Path & "\brody1.avi")

    Me.Timer1.Interval = 1000
    Me.Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Dim videoIsPlaying As Boolean

    videoIsPlaying = Me.WindowsMediaPlayer1.PlayState = wmppsPlaying

    If Not videoIsPlaying Then
        Me.Timer1.Enabled = False
        'Hide it here
    End If

End Sub

Marc
  • 973
  • 4
  • 13