Results 1 to 5 of 5

Thread: [RESOLVED] Trying to detect when a video has ended.

  1. #1

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    112

    Resolved [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

  2. #2
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    3,560

    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.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  3. #3

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    112

    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.
    Last edited by Mugsy323; Jul 14th, 2025 at 12:06 PM.

  4. #4
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    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.

  5. #5

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    112

    Re: [RESOLVED] Trying to detect when a video has ended.

    (Thx for the reply.)

    "PlayState changed."

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