[RESOLVED] Trying to detect when a video has ended.
I'm writing an app that plays a video (embedded WMP) when a form loads. Works fine.
But I can't detect when the video has ended. I've tried everything I can find online. Even asked GitHubAI. Nothing works.
Code:
Public Class frmSelect
Dim bolPlaying As Boolean = False
Private Sub frmSelect_Load(sender As Object, e As EventArgs) Handles MyBase.Load
wmpVideo.URL = "O:\Video\video.mp4"
wmpVideo.settings.setMode("loop", False)
bolPlaying = True
' ("bolPlaying" flag optional. Added to make sure "PlayStateChange" Event is ignored
' when video starts.)
End Sub
...
Private Sub wmpVideo_PlayStateChange(sender As Object, e As _WMPOCXEvents_PlayStateChangeEvent) Handles wmpVideo.PlayStateChange
If bolPlaying and wmpVideo.playState.wmppsStopped Then MsgBox("Video has ended.")
' Tried: playState.wmppsMediaEnded, playState.wmppsWaiting, playState.wmppsPaused
' Also tried checking the "_EndOfStream" Event.
End Sub
The moment the form loads, my "PlayState" check comes back "True" and my MsgBox test appears regardless of what I check for (see Comment at bottom of code.)
How do I detect the end of a video? TIA
Re: Trying to detect when a video has ended.
You can, with the file size and knowing the type/quality of the specific media, calculate the duration.
Re: Trying to detect when a video has ended.
Thx for the reply.
Unfortunately, I tried that and it didn't work. For some reason I can't figure out, I can't compare the "CurrentPosition" to the "Duration" to tell when it's done. Very aggravating.
I finally devised a "quick & dirty" solution: I count the times the "PlayStateChange" Event changes. It changes on Load, Playing, and Stopped. So I increment a counter every time it changes. When the counter reaches 3 (the 3rd change), I know it's done.
Any ugly solution, but it works. :p
Re: [RESOLVED] Trying to detect when a video has ended.
What is the value of e when the PlayState event is raised? Usually the parameter to an event will contain relevant information.
https://learn.microsoft.com/en-us/pr...laystatechange seems to indicate you should be able to get this from the information provided.
Re: [RESOLVED] Trying to detect when a video has ended.
(Thx for the reply.)
"PlayState changed." :D