2011-04-05 69 views
1

我可以把視頻放在我的窗體中。c#使用Microsoft.DirectX.AudioVideoPlayback如何播放下一個視頻完成後

我的問題是我如何使它完成播放視頻時,它開始播放另一個視頻?意思就像一個序列。完成後,播放另一個視頻。

到目前爲止,我已經設法播放視頻,它只是循環播放視頻。

有什麼想法?

這是我到目前爲止的代碼:

public partial class Form1 : Form 
{ 
    Video video; 



    public Form1() 
    { 
     InitializeComponent();   
     Initializevid1(); 

    } 

    public void Initializevid1() 
    { 

      // store the original size of the panel 
      int width = viewport.Width; 
      int height = viewport.Height; 

      // load the selected video file 
      video = new Video("C:\\Users\\Dave\\Desktop\\WaterDay1.wmv"); 

      // set the panel as the video object’s owner 
      video.Owner = viewport; 

      // stop the video 
      video.Play(); 
      video.Ending +=new EventHandler(BackLoop); 

      // resize the video to the size original size of the panel 
      viewport.Size = new Size(width, height); 

    } 

    private void BackLoop(object sender, EventArgs e) 
    { 

     //video.CurrentPosition = 0; 
    } 
+0

視口是什麼類型的控件? – MPelletier 2011-04-12 09:51:50

回答

0

您可以使用之前創建要打開BackLoop()函數的第二個視頻文件的同一視頻對象。

所以,代碼看起來應該像什麼這樣的:

private void BackLoop(object sender, EventArgs e) 
{ 
    video.Open("C:\\Users\\Dave\\Desktop\\WaterDay2.wmv", true); 
} 
1

當AudioVideoPlayback播放視頻序列:

  1. 創建的視頻列表進行顯示(使用文件路徑),最好在一個列表框中。

  2. 使用整數從listbox.items索引獲取文件路徑。

  3. 確保在加載下一個視頻之前放置視頻。

  4. 每次播放視頻時遞增整數。

  5. 使用if語句來查看它是否是序列的結尾。

  6. 由於個人喜好(不知道它有多大的重要性),我會調整視頻播放

所以從您的代碼之前:(沒有測試過這一點,但在理論上,我認爲這應工作)

public partial class Form1 : Form 
    { 
     Video video; 
     Int SeqNo = 0; 

     public Form1() 
     { 
      InitializeComponent();   
      Initializevid1(); 

     } 

     public void Initializevid1() 
     { 

       // store the original size of the panel 
       int width = viewport.Width; 
       int height = viewport.Height; 

       // load the selected video file 
       video = new Video(listbox1.Items[SeqNo].Text); 

       // set the panel as the video object’s owner 
       video.Owner = viewport; 

       // resize the video to the size original size of the panel 
       viewport.Size = new Size(width, height); 

       // stop the video 
       video.Play(); 

       // start next video 
       video.Ending +=new EventHandler(BackLoop); 
     } 

     private void BackLoop(object sender, EventArgs e) 
     { 
      // increment sequence number 
      SeqNo += 1;   //or '++SeqNo;' 

      //check video state 
      if (!video.Disposed) 
      { 
       video.Dispose(); 
      } 

      //check SeqNo against listbox1.Items.Count -1 (-1 due to SeqNo is a 0 based index) 
      if (SeqNo <= listbox1.Items.Count -1) 
      { 


       // store the original size of the panel 
       int width = viewport.Width; 
       int height = viewport.Height; 

       // load the selected video file 
       video = new Video(listbox1.Items[SeqNo].Text); 

       // set the panel as the video object’s owner 
       video.Owner = viewport; 

       // resize the video to the size original size of the panel 
       viewport.Size = new Size(width, height); 

       // stop the video 
       video.Play(); 


       // start next video 
       video.Ending +=new EventHandler(BackLoop); 
      } 
     } 
0

我用這篇文章,以使其適應我的需要,這是我的解決方案:

Video _SegaVideo; 
Video _IntroVideo; 

public _FrmMain() 
{ 
    InitializeComponent(); 

    _SegaVideo = new Video(@"video\SEGA.AVI"); 
    _SegaVideo.Owner = _VideoPanel; 
    _SegaVideo.Play(); 
    _SegaVideo.Ending += new EventHandler(_SegaVideoEnding); 

} 

private void _SegaVideoEnding(object sender, EventArgs e) 
{ 
    _IntroVideo = new Video(@"video\INTRO.AVI"); 
    _IntroVideo.Owner = _VideoPanel; 
    _IntroVideo.Play(); 
} 
相關問題