C#-播放来自wmp组件中资源的视频 [英] C# - Play videos from resources in wmp component

查看:166
本文介绍了C#-播放来自wmp组件中资源的视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#Windows窗体中有一个wmp组件,我希望它从解决方案的资源中播放视频(.avi).我需要知道wmp组件的代码才能找到视频.有建议吗?

I have a wmp component in a C# Windows Forms and i want it to play a video (.avi) from the solution's resources. I need to know the code for the wmp component to find the video. Suggestions?

推荐答案

当前有一种方法可以流式传输文件.

Currently there is a way over streaming the file.

首先,我们需要一个始终应有的地方

First of all, we need a place where it should be always possible

        string streamPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\";

下一步是MediaPlayer的实例

Next Step an Instance of the MediaPlayer

    WindowsMediaPlayer wmp = new WindowsMediaPlayer();

然后,我们需要流式传输汇编资源

Then we need to stream the Assembly Resource

    Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Smartis.Resources.Natur.wmv");

    using (Stream output = new FileStream (streamPath + "mediafile.avi", FileMode.Create))
    {
        byte[] buffer = new byte[32*1024];
        int read;

        while ( (read= stream.Read(buffer, 0, buffer.Length)) > 0)
        {
            output.Write(buffer, 0, read);
        }
    }

最后,我们应该能够加载文件了.

Finally we should be able to load the file.

    wmp.URL = streamPath + "mediafile.avi";
    wmp.controls.play();


播放后,别忘了清除文件夹:


After playing don't forget to clear the folder:

    File.Delete(streamPath + "mediafile.avi");

这篇关于C#-播放来自wmp组件中资源的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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