如何在c#中将视频文件存储在exe文件中并播放

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

我正在使用 c# 中的 winForms。我想在不使用任何加载对话框或 select 的情况下从资源访问视频文件。这意味着我想直接将视频文件存储在 EXE 文件中。

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

我在执行这段代码时收到警告。警告是“byte[] 与文件格式不匹配”​​请帮我 运行 这段代码。

谢谢。

步骤:

  1. 将您的文件添加为资源。
  2. 将 Windows Media Player 添加到您的工具箱,然后将其放在 Form 上。
  3. 编写此代码以播放您的嵌入式视频

代码:

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

截图:

更多信息: