How to perform vba task after media player finishes

3.5k views Asked by At

I'm using Access 2010 and have tables setup to identify a particular video file. I have a button on a form that will launch the video file with WindowsMediaPlayer. The problem is that I want to update the table(s) after the video has run. I've created this quick from a button on a form (fTest1) but the next part I've been searching around for a while.

Private Sub Command1_Click()
Dim player As WindowsMediaPlayer

DoCmd.OpenForm "fTest2"

Set player = Forms!fTest2!WMP.Object
Forms!fTest2!WMP.URL = "S:\Training Videos\Wildlife.wmv"

' here is where I want to do something after the file has finished
' 

I did a test with a msgbox but it shows up while the video is playing. Looking for like a call or wait until or something.

Any help would be appreciated.

3

There are 3 answers

0
Costas in AZ On BEST ANSWER

After stumbling around testing I found a post at access-programmers.co.uk by a ghudson for the following function.

Public Function Pause(NumberOfSeconds As Variant)
On Error GoTo Err_Pause

Dim PauseTime As Variant, start As Variant

PauseTime = NumberOfSeconds
start = Timer
Do While Timer < start + PauseTime
DoEvents
Loop

Exit_Pause:
Exit Function

Err_Pause:
MsgBox Err.Number & " - " & Err.Description, vbCritical, "Pause()"
Resume Exit_Pause

End Function

Private Sub Command1_Click()
Dim player As WindowsMediaPlayer
Dim VideoDone As String

DoCmd.OpenForm "fTest2"

Set player = Forms!ftest2!WMP.Object
Forms!ftest2!WMP.URL = "S:\Training Videos\Wildlife.wmv"

VideoDone = "No"
Pause 5

Do While VideoDone = "No"
Pause 2
If player.playState = wmppsStopped Then VideoDone = "Yes"
Loop

player.Close
DoCmd.Close acForm, "fTest2"

End Sub

The button is on a test form called "fTest1". I get no "not responding" or busy "circles". Works like a charm.

1
Johnny Bones On

The only way that would possibly work is if you knew the length of the video. Then you could put an OnTimer event to "put the computer to sleep" for the specified amount of time.

0
topher23 On

Another possibility would be to simply use the DoEvents loop based on wmppsStopped and cut out the Pause function middleman:

Do Until player.playState = wmppsStopped
    DoEvents
Loop

This just keeps a loop going but passes control to the console (so Access and Windows aren't "locked up") until the video hits the end. Just make sure the user can't close the form: remove the control box and make the form modal to ensure they don't hide it.