如何使用启动画面显示视频
问题描述:
我想在c#中加载启动画面时显示视频(.mp4)文件。我试过跟随我能够播放音频,但视频没有显示在屏幕上。不确定我是否需要添加任何其他内容来显示视频。
我尝试了什么:
I would like to display a video (.mp4) file while splash screen is being loaded in c#. I tried following i was able to get the audio to play however the video is not displayed on the screen. Not sure if i need to add anything else to display the video.
What I have tried:
private void SplashScreen_Load(object sender, EventArgs e)
{
timer1.Start();
PlayFile(@"D:\Logo.mp4");
}
//Trying to add video.
WMPLib.WindowsMediaPlayer Player;
private void PlayFile(String url)
{
Player = new WMPLib.WindowsMediaPlayer();
Player.PlayStateChange +=
new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(Player_PlayStateChange);
Player.MediaError +=
new WMPLib._WMPOCXEvents_MediaErrorEventHandler(Player_MediaError);
Player.URL = url;
Player.controls.play();
}
private void Player_PlayStateChange(int NewState)
{
if ((WMPLib.WMPPlayState)NewState == WMPLib.WMPPlayState.wmppsStopped)
{
this.Close();
}
}
private void Player_MediaError(object pMediaObject)
{
MessageBox.Show("Cannot play media file.");
this.Close();
}
答
您没有在表单上放置控件以使视频可见,媒体play只存在于PlayFile
方法的范围内。
本文可能会帮助你:音频和视频播放器C#Winform [ ^ ]
You have not place a control on the form to make the video visible, the media play only exists within the scope of thePlayFile
method.
This article might help you along: Audio and Video Player C# Winform[^]