Play&从表单控件winform暂停视频

时间:2014-03-07 02:10:04

标签: c# .net winforms video powerpoint-2007

我想制作一个能够开始,暂停,停止,关闭测验演示的表单控件(按下开始时将运行倒计时时间)。问题出在一些演示文稿中,有可用的视频(每张幻灯片最多只能包含1个视频,而不是每个幻灯片都包含它)。

这些是我用于在createPresentation方法中添加视频的一些代码段:

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);

到目前为止,我已经尝试过这个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;
        }
    }
}

但是结果却给了我一个错误:

  

无效参数无法转换   Microsoft.Office.Interop.PowerPoint.Slide to   Microsoft.Office.Interop.PowerPoint.Shape

我想要实现的目标是一个表单控件,可以在用户按下开始按钮(倒计时)时播放视频,而不是在幻灯片播放时自动播放。


更新

我试过这个。该程序可以正常运行,但视频仍未播放。

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;
    }
}

更新 @jonPall

我试过这个:

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;

我的程序可以正常运行,但是当我按下开始(播放视频和运行倒数计时器)时,它会给出错误

  

序列(未知成员):非法值。对象不存在。


更新 @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;
    }
}

使用上面的脚本我可以检测活动幻灯片中是否包含视频 但是〜var~playVideo在幻灯片中仍为null包含视频
我失踪的地方?

1 个答案:

答案 0 :(得分:1)

试试这个:

 playVideo.Timing.TriggerType = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;