简体   繁体   English

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

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

I am working with winForms in c#.我在 c# 中使用 winForms。 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.这意味着我想直接将视频文件存储在 EXE 文件中。

 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.将 Windows Media Player 添加到您的工具箱,然后将其放在 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:更多信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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