2014-03-07 78 views
16

我想創建一個能夠開始,暫停,停止,關閉測驗演示的窗體控件(按下開始時按倒數計時的時間)。問題是在一些演示中,有可用的視頻(每張幻燈片最多隻能包含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到 Microsoft.Office.Interop.PowerPoint.Shape

我想達到的目標是一個表單控件,當用戶按下啓動按鈕,可以播放視頻(倒計時運行)幻燈片播放時不自動播放。


UPDATE

我想這一個。該程序可以無誤運行,但視頻仍然沒有播放。

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

我想這一個:

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; 

我的程序可以運行沒有錯誤,但是當我按下啓動(播放視頻&運行倒計時定時器)它給錯誤

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


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

與上面的腳本,我可以在活動的幻燈片,如果檢測含有視頻或不
而是〜VAR〜的playVideo幻燈片還是空包含視頻
我在哪裏失蹤?

+2

你嘗試: playVideo.Timing.TriggerType = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious; – JonPall

+1

@JonPall請檢查我的更新信息...也許你可以幫我定義正確的playVideo – Neversaysblack

+1

oSlide對象在你的更新中爲null,因此你得到一個nullref異常。 – JonPall

回答

1

試試這個:

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

是的我猜如果我的playVideo可以修復那個腳本可以運行(許多人建議我腳本),但是問題是我的playVideo var似乎有問題 – Neversaysblack

相關問題