如何在C#的exe文件中存储视频文件并播放 [英] How to store a video file in exe file in c# and play it

查看:73
本文介绍了如何在C#的exe文件中存储视频文件并播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#中的winForms.我想从资源访问视频文件,而不使用任何对话框进行加载或选择.这意味着我想直接将视频文件存储在EXE文件中.

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

我在执行此代码时收到警告.警告是"byte []与文件格式不匹配"​​,请帮助我运行此代码.

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.

谢谢.

推荐答案

步骤:

  1. 将文件添加为资源.
  2. 将Windows Media Player添加到您的工具箱中,然后将其放在窗体上.
  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();
}

截屏:

更多信息:

这篇关于如何在C#的exe文件中存储视频文件并播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆