从窗体控制winform播放和暂停视频?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (202)

我想做一个表单控件,可以启动,暂停,停止,关闭测验演示(按下开始时按倒计时时间运行)。问题是在一些演示中,有可用的视频(每张幻灯片最多只能包含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);

到目前为止,我已经尝试:

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

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

invalid arguments cannot convert from 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;
    }
}

我试过这个:

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;

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

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

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;
    }
}
提问于
用户回答回答于
 playVideo.Timing.TriggerType = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;

所属标签

可能回答问题的人

  • 人生的旅途

    10 粉丝484 提问6 回答
  • 无聊至极

    4 粉丝504 提问6 回答
  • 富有想象力的人

    4 粉丝0 提问4 回答
  • 找虫虫

    2 粉丝0 提问4 回答

扫码关注云+社区

领取腾讯云代金券