16

I want to make a form control which be able to start, pause, stop, close quiz presentation (count down time will run when start is pressed). The problem is in some presentations, there is available video (each slide can only contain a maximum of 1 video, and not every slide contains it).

These are some code snippets I used for add video in createPresentation method:

PowerPoint.Slides oSlides = null;
PowerPoint.Slide oSlide = null;
int ctrSoal = 0;
foreach (CQuestion myQuestion in Global.questions)
{
    ctrSoal++;
    oSlides = oPre.Slides;
    oSlide = oSlides.Add(ctrSoal,   PowerPoint.PpSlideLayout.ppLayoutTextAndTwoObjects);

    oShape2 = oSlide.Shapes[4];
    oSlide.Shapes.AddMediaObject(System.IO.Path.Combine(Global.myVideoLocation, myQuestion.video), oShape2.Left, oShape2.Top, oShape2.Width, oShape2.Height);

So far I already tried some solutions from this link

private void startToolStripMenuItem_Click(object sender, EventArgs e)
{
    PowerPoint.Slides oSlides = null;
    PowerPoint.Slide oSlide = null;
    int ctrSoal = 0;
    foreach (CQuestion myQuestion in Global.questions)
    {
        ctrSoal++;
        oSlides = oPre.Slides;
        oSlide = oSlides.Add(ctrSoal, PowerPoint.PpSlideLayout.ppLayoutTextAndTwoObjects);
        var playVideo = oSlide.TimeLine.MainSequence.FindFirstAnimationFor(oSlide);
    }

    questionIndex = oPre.SlideShowWindow.View.Slide.SlideIndex - 1;
    questionId = myQuiz.questions[questionIndex].id;
    if (labelTimer.Text != "Paused")
    {
        duration = 0;
        duration += myQuiz.questions[questionIndex].durationMinute * 60;
        duration += myQuiz.questions[questionIndex].durationSecond;
        labelKeypadID.Text = "";
        for (int i = 0; i < jumlahJawaban; i++)
        {
            arrChart[i] = 0;
        }
    }
}

But it's giving me an error as a result:

invalid arguments cannot convert from Microsoft.Office.Interop.PowerPoint.Slide to Microsoft.Office.Interop.PowerPoint.Shape

The goal I want to achieve is a form control that can play video when user presses the start button (count down running) not auto-playing when the slideshow is run.


UPDATE

I tried this one. The program can running without error but the video is still not playing.

PowerPoint.Shapes objShapes = null;
objShapes = oPre.Slides[1].Shapes;
foreach (Microsoft.Office.Interop.PowerPoint.Shape s in objShapes)
{
    if (s.Name.Contains(".wmv"))
    {
        s.AnimationSettings.PlaySettings.PlayOnEntry = Office.MsoTriState.msoTrue;
    }
}

UPDATE @jonPall

I tried this one:

PowerPoint.Slide oSlide = null;
PowerPoint.Shape objShape = null;
PowerPoint.Slides oSlides = null;
PowerPoint.Shapes objShapes = null;

int ctrSoal = 1;
oSlides = oPre.Slides;
oSlide = oSlides.Add(ctrSoal, PowerPoint.PpSlideLayout.ppLayoutTextAndTwoObjects);
objShapes = oPre.Slides[1].Shapes;

var playVideo = oSlide.TimeLine.MainSequence.FindFirstAnimationFor(objShape);
playVideo.Timing.TriggerType = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;

My program can run without error, but when I press start (to play video & run countdown timer) it's give error

Sequence (unknown member) : Illegal value. Object does not exist.


UPDATE @Andy

PowerPoint.Slide oSlide = null;
PowerPoint.Slides oSlides = null;
PowerPoint.Shapes objShapes = null;

int ctrSoal = 1;
oSlides = oPre.Slides;
oSlide = oSlides.Add(ctrSoal, PowerPoint.PpSlideLayout.ppLayoutTextAndTwoObjects);

int indexSlide = oPre.SlideShowWindow.View.Slide.SlideIndex;
objShapes = oPre.Slides[indexSlide].Shapes;

foreach (Microsoft.Office.Interop.PowerPoint.Shape objShape in objShapes) {
    string extension = Path.GetExtension(objShape.Name);
    if (extension == ".wmv") {
         //MessageBox.Show("Video Available");
         var playVideo = oSlide.TimeLine.MainSequence.FindFirstAnimationFor(objShape);
         playVideo.Timing.TriggerType = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;
    }
}

with above script i can detect if in active slide contain video or not
but ~var~ playVideo still null in slide contain video
where i'm missing?

Community
  • 1
  • 1
Surya Matadewa
  • 1,017
  • 5
  • 19
  • 38
  • 2
    Did you try: playVideo.Timing.TriggerType = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious; – JonPall Mar 10 '14 at 00:27
  • 1
    @JonPall please check my update post...maybe u can help me with define correct playVideo – Surya Matadewa Mar 10 '14 at 01:35
  • 1
    the oSlide object is null in your update, hence you get a nullref exception. – JonPall Mar 10 '14 at 19:09
  • 1
    @JonPall please check my update post again :D – Surya Matadewa Mar 11 '14 at 09:31
  • In your update `objShape` passed to `FindFirstAnimationFor` is null :) – JonPall Mar 11 '14 at 21:54
  • @JonPall objShapes = oPre.Slides[1].Shapes; – Surya Matadewa Mar 12 '14 at 01:13
  • objShape is still null after you assign to objShapes. – JonPall Mar 12 '14 at 05:53
  • @JonPall can u give me reference (link or example) how to assign objShapes & oSlide? – Surya Matadewa Mar 12 '14 at 05:59
  • 1
    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.sequence.findfirstanimationfor%28v=office.14%29.aspx. Try `objShape = objShapes.Item[0];` before your call to `FindFirstAnimationFor`. And don't forget errorhandling. – JonPall Mar 12 '14 at 06:17
  • @JonPall in my objShape or objShapes it's not available item....where is i'm missing? – Surya Matadewa Mar 12 '14 at 06:20
  • Small note besides: You might use [Path.GetExtension()](http://msdn.microsoft.com/de-de/library/system.io.path.getextension(v=vs.110).aspx) instead of `s.Name.Contains(".wmv")` – Andy Mar 27 '14 at 08:28
  • In what line does `Sequence (unknown member) : Illegal value. Object does not exist.` appear? – Andy Mar 27 '14 at 08:40
  • @Andy in line "var playVideo = oSlide.TimeLine.MainSequence.FindFirstAnimationFor(objShape);" i think my program can't detect video in slide...but with first update i successfully detect video – Surya Matadewa Mar 28 '14 at 01:11
  • @Neversaysblack Of course this exception appears. You never set `objShape` but you give it to `oSlide.TimeLine.MainSequence.FindFirstAnimationFor(objShape)`. – Andy Mar 28 '14 at 08:26
  • What did you mean with 'in my objShape or objShapes it's not available item'? – Andy Mar 28 '14 at 08:26
  • @andy i tried to assign ~objShape = objShapes.item[0]~ but my objShapes does not have ~.item~ – Surya Matadewa Apr 21 '14 at 03:02

1 Answers1

1

Try this:

 playVideo.Timing.TriggerType = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;
  • yeah i guess if my playVideo can fixed that script can running (many people suggest me that script) but the problem is my playVideo var seem have problem – Surya Matadewa Apr 21 '14 at 03:04