How to store a video file in exe file in c# and play it

二次信任 提交于 2019-12-20 06:15:27

问题


I am working with winForms in c#. I want to access video file from resources without using any dialog box for load or select. That means I want directly store video file in EXE file.

 private void startBtn_Click(object sender, EventArgs e) 
 {  
      axWindowsMediaPlayer1.URL=(videoForms.Properties.Resources.Airtel.wmv).ToString();
      axWindowsMediaPlayer1.Ctlcontrols.play();  
 }

I get warning while I execute this code. the warning is " byte[] that does not matches the file format" please help me to run this code.

Thank you.


回答1:


Steps:

  1. Add your file as a resource.
  2. Add Windows Media Player to your toolbox and then put it on Form.
  3. Write this code to play your embedded video

Code:

private void Form_Load(object sender, EventArgs e)
{
    var file=System.IO.Path.Combine(Application.StartupPath, "YourFileName.wmv");
    if (!System.IO.File.Exists(file))
        System.IO.File.WriteAllBytes(file, Properties.Resources.YourFileName);

    this.axWindowsMediaPlayer1.URL = file;
    this.axWindowsMediaPlayer1.Ctlcontrols.play();
}

Screenshot:

More information:

  • Using the Windows Media Player Control in a .NET Framework Solution
  • Object Model Reference for Visual Basic .NET and C#


来源:https://stackoverflow.com/questions/32286400/how-to-store-a-video-file-in-exe-file-in-c-sharp-and-play-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!