C#-播放wmp组件中资源中的视频

C#-播放wmp组件中资源中的视频,c#,video,resources,wmp,C#,Video,Resources,Wmp,我在C#Windows窗体中有一个wmp组件,我希望它能够播放解决方案资源中的视频(.avi)。我需要知道wmp组件的代码才能找到视频。建议?目前有一种方法可以对文件进行流式处理 wmp.URL = streamPath + "mediafile.avi"; wmp.controls.play(); 首先,我们需要一个永远可能的地方 string streamPath = Environment.GetFolderPath(Environment.Special

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

目前有一种方法可以对文件进行流式处理

    wmp.URL = streamPath + "mediafile.avi";
    wmp.controls.play();
首先,我们需要一个永远可能的地方

        string streamPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\";
下一步是MediaPlayer的实例

    WindowsMediaPlayer wmp = new WindowsMediaPlayer();
然后,我们需要流式处理程序集资源

    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);
        }
    }
最后,我们应该能够加载该文件

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

播放后,不要忘记清除文件夹:

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

目前有一种方法可以通过流式传输文件

    wmp.URL = streamPath + "mediafile.avi";
    wmp.controls.play();
首先,我们需要一个永远可能的地方

        string streamPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\";
下一步是MediaPlayer的实例

    WindowsMediaPlayer wmp = new WindowsMediaPlayer();
然后,我们需要流式处理程序集资源

    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);
        }
    }
最后,我们应该能够加载该文件

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

播放后,不要忘记清除文件夹:

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

落选票来了…到目前为止你做了什么?发布一些代码。@Brian总是一样--别忘了使用WMPLib添加投票结果出来了…到目前为止你做了什么?发布一些代码。@Brian总是一样--别忘了使用WMPLib添加这不起作用,因为视频不在URL中,它在程序的资源中。先生们,我很好奇。但现在我注意到你了。UpvoteThis不起作用,因为视频不在URL中,它在程序的资源中先生们,你们有我的好奇心。但现在我注意到你了。向上投票