简体   繁体   中英

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

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.

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM