Autoplaying a movie in a PowerPoint presentation with C#
Asked Answered
C

2

0

I am currently trying to change some settings in a .pptx files via C# and Microsoft.Office.Interop.PowerPoint. I have some .wmv movies linked on several slides of the presentation. At the time the presentations were created, all movies play as soon as they are clicked. However, I want to change this to start automatically playing as soon as the slide is viewed. This this has to be done to a lot of presentations, so there is no way to do this manually.

I found the PlaySettings.PlayOnEntry property, but I can't figure out how to use it. I found several examples how to do this with a new movie to be embedded (and then, only for Visual Basic), but since the movies are already embedded, this is not what I want.

I also have no idea how I can actually access any objects on the current slide, maybe there is a way to check if a shape is a video-file and then change above setting, but the MSDN-Reference is not very helpful on Office-Topics. I'm using Powerpoint 2007 and Visual Studio 2010 if that matters.

Crossbar answered 13/12, 2010 at 12:39 Comment(0)
C
1

Got it. Searching through all shapes of the Presentation and filtering out the movies works:

//While iterating through all slides i:
   objShapes = objPres.Slides[i].Shapes;
    foreach (Microsoft.Office.Interop.PowerPoint.Shape s in objShapes) {
            if(s.Name.Contains(".wmv")){
            s.AnimationSettings.PlaySettings.PlayOnEntry = MsoTriState.msoTrue;
    }
   }
Crossbar answered 13/12, 2010 at 17:41 Comment(1)
Great to hear it is sorted. You can accept your own answer by clicking the hollow checkmark next to the up/down arrows on this answer. When you have a chance, take an opportunity to read through the FAQ @ stackoverflow.com/faq.Sanjiv
H
2

@Lennart's solution is part of it, you then need a page trigger

var videoAnimation = slide.TimeLine.MainSequence.FindFirstAnimationFor(objShapes);
if (videoAnimation != null)
{
    videoAnimation.Timing.TriggerType = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;
}
Helpless answered 8/7, 2012 at 10:34 Comment(0)
C
1

Got it. Searching through all shapes of the Presentation and filtering out the movies works:

//While iterating through all slides i:
   objShapes = objPres.Slides[i].Shapes;
    foreach (Microsoft.Office.Interop.PowerPoint.Shape s in objShapes) {
            if(s.Name.Contains(".wmv")){
            s.AnimationSettings.PlaySettings.PlayOnEntry = MsoTriState.msoTrue;
    }
   }
Crossbar answered 13/12, 2010 at 17:41 Comment(1)
Great to hear it is sorted. You can accept your own answer by clicking the hollow checkmark next to the up/down arrows on this answer. When you have a chance, take an opportunity to read through the FAQ @ stackoverflow.com/faq.Sanjiv

© 2022 - 2024 — McMap. All rights reserved.