Addin to determine when a Windows Media Player object has finished.

M

Mike M.

I am testing an addin to do the following:

Public WithEvents PPTEvent As Application
' See if I can get events from this object
Public WithEvents wmpObject As WindowsMediaPlayer

1. In SlideShowNextSlide, detect a Windows Media Player shape on a slide.
2. Set slide.SlideShowTransition.AdvanceOnTime = msoFalse
3. Set a reference to the WMP object and catch it's events.
4. In the WMP PlayStateChange event catch the wmppsStopped event and advance
the slide.

This works intermittently, sometimes the video clip doesn't start
automatically. Also, I don't want to leave the wmpObject set because I
think it will leak memory. I tried setting it to nothing but that causes PPT
to crash when the slide show finishes. I have also read some warnings about
doing anything in the WMP event functions that affects the object's state.
I think advancing the slide probably does that.

I am going to investigate using the Windows timer API to set a timer,
reacquire the WMP object and check it's state to see how that does. I don't
think it is as efficient as using the player object events though.

Anyone messed around with this before and has any suggestions to offer?

TIA
 
J

John Langhans [MSFT]

[CRITICAL UPDATE - Anyone using Office 2003 should install the critical
update as soon as possible. From PowerPoint, choose "Help -> Check for
Updates".]

Hello,

If you (or anyone else reading this message) have suggestions for how to
make this easier to do in PowerPoint (perhaps being able to accomplish the
same end-result without requiring VBA <hint>), don't forget to send your
feedback (in YOUR OWN WORDS, please) to Microsoft at:

http://register.microsoft.com/mswish/suggestion.asp

It's VERY important that, for EACH wish, you describe in detail, WHY it is
important TO YOU that your product suggestion be implemented. A good wish
submssion includes WHAT scenario, work-flow, or end-result is blocked by
not having a specific feature, HOW MUCH time and effort ($$$) is spent
working around a specific limitation of the current product, etc. Remember
that Microsoft receives THOUSANDS of product suggestions every day and we
read each one but, in any given product development cycle, there are ONLY
sufficient resources to address the ones that are MOST IMPORTANT to our
customers so take the extra time to state your case as CLEARLY and
COMPLETELY as possible so that we can FEEL YOUR PAIN.

IMPORTANT: Each submission should be a single suggestion (not a list of
suggestions).

John Langhans
Microsoft Corporation
Supportability Program Manager
Microsoft Office PowerPoint for Windows
Microsoft Office Picture Manager for Windows

For FAQ's, highlights and top issues, visit the Microsoft PowerPoint
support center at: http://support.microsoft.com/default.aspx?pr=ppt
Search the Microsoft Knowledge Base at:
http://support.microsoft.com/default.aspx?pr=kbhowto

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
M

Mike M.

o.k. Done. Anybody have some suggestions for my addin? I am having trouble
getting my PowerPoint with events to play nicely with the WMP object. Many
times it doesn't auto start the movie when I run the show.
 
M

Mike M.

I am testing just trying to recognize the WMP object and stop the slide form
advancing on time. The code below works if the first slide does NOT contain
a WMP object. If the first slide contains a WMP object the show seems to
get stuck in a loop doing next slide with slide 1. If I comment out the
code to set the AdvanceOnTime property then it works fine but of course
advances before the movie is finished. Why would setting that property
cause the show to malfunction?

Public WithEvents PPTEvent As Application

Private Sub PPTEvent_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
Dim slide As PowerPoint.slide
Dim shp As PowerPoint.Shape
Dim shapeType As Integer
Dim progID As String
Dim wmpObject As WindowsMediaPlayer

' This contains the current slide.
Set slide = Wn.View.slide

LogIt "Next slide event for slide " & slide.SlideNumber & "."

' Check each shape for special ones
For Each shp In slide.Shapes
With shp
' See if it is an OLE WMP active x control.
shapeType = .Type
If (shapeType = 12) Then
progID = .OLEFormat.progID
If (progID = "WMPlayer.OCX.7") Then
LogIt "Found WMP shape."
Set wmpObject = .OLEFormat.Object
If (wmpObject.Name = "WindowsMediaPlayer1") Then
' Don't let this slide advance on time. Do it when
video done
' slide.SlideShowTransition.AdvanceOnTime = msoFalse
' slide.SlideShowTransition.AdvanceOnClick = msoTrue
End If
End If
End If
End With
Next shp

LogIt "Exit function."

End Sub

Here is the log for when the code is commented out and it works:
Next slide event for slide 1.
Found WMP shape.
Exit function.
Next slide event for slide 2.
Exit function.
Next slide event for slide 3.
Exit function.

Here is when it is in and doesn't work:
Next slide event for slide 1.
Found WMP shape.
Exit function.
Next slide event for slide 1.
Found WMP shape.
Exit function.
Next slide event for slide 1.
Found WMP shape.
Exit function.
Next slide event for slide 1.
Found WMP shape.
Exit function.
Repeats until I terminate with Task Manager.
 
M

Mike M.

Hey Mike, there seems to be some problem with when the SlideShowNextSlide
event actually occurs or some such thing. If you put the same code in the
SlideShowBegin and don't do in SlideShowNextSlide for slide 1 then it works.
Why? I don't know but it does make it more difficult.

HTH ;-)
 
S

Steve Rindsberg

So good of you to stop by and help Mike solve his problems. ;-)

Remind me which version of PPT this is? And if 2003, have you tried the same
code in 2002 or 2000?
 
M

Mike M.

Always willing to help Mikey. PPT 2002. I have a draft copy of it working
now. It is wierd in that you can't do anything in the media player event
routines that affects the play state so I have to set a flag, set a timer,
catch the timer, check the flag, advance the slide, jump off a cliff, go to
the local cinema, talk to Mary Lou......

Oh yeah, and Eat Sauteed Sea Worms!!!!! :-O
 
S

Steve Rindsberg

Always willing to help Mikey. PPT 2002. I have a draft copy of it working
now. It is wierd in that you can't do anything in the media player event
routines that affects the play state so I have to set a flag, set a timer,
catch the timer, check the flag, advance the slide, jump off a cliff, go to
the local cinema, talk to Mary Lou......

Ug Lee. But ugly working is better than pretty and not, I guess.
Oh yeah, and Eat Sauteed Sea Worms!!!!! :-O

S'awright, you'cn have mine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top