C# load video from resources folder not playing

痞子三分冷 提交于 2020-01-05 08:31:51

问题


I trying to load my video from the resources folder but its not playing automatically once my form load. Can I know what mistake i have done. Thank you.

This is my c# code:

 private void Form2_Load(object sender, EventArgs e)
    {
        axWindowsMediaPlayer1.URL = @"Resources/abc.mp4";

        axWindowsMediaPlayer1.Ctlcontrols.play();
    }

回答1:


Well I have solved it my ownself. Actually, I accidentally added the @ symbol into my url. That causes the problem. This is the updated code.

private void Form2_Load(object sender, EventArgs e)
{
    axWindowsMediaPlayer1.URL = "Resources\\abc.mp4";

    axWindowsMediaPlayer1.Ctlcontrols.play();
}



回答2:


To do that king of thing, you must get the stream of your resource. So that code should work for you because works for me :)

// temporary file path - your temp file = video.avi
 var strTempFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Video.avi");

        try
        {
            // ResourceName = the resource you want to play
            File.WriteAllBytes(strTempFile, Properties.Resources.ResourceName);
            axWMP.URL = strTempFile;
            axWMP.Ctlcontrols.play();
        }
        catch (Exception ex)
        {

            // Manage me
        }

You can implement a axWMP_PlayStateChange method to remove video.Avi at the end.

Hope it could help you



来源:https://stackoverflow.com/questions/32094176/c-sharp-load-video-from-resources-folder-not-playing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!