本文介绍了我怎么能播放视频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我喜欢玩视频文件,如AVI文件,通过我的C#程序。是否可以播放视频文件那样?
I like to play video files, such as AVIs, through my C# program. Is it possible to play video files like that?
推荐答案
您应该能够使用媒体播放器控制播放媒体文件。
You should be able to use the Media Player control to play media files.
从http://msdn.microsoft.com/en-us/library/dd562692(VS.85).aspx,你应该能够以适应视频:
Example of playing audio from http://msdn.microsoft.com/en-us/library/dd562692(VS.85).aspx, you should be able to adapt it to video:
// [ C# ]
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 Form1_Load(object sender, System.EventArgs e)
{
// TODO Insert a valid path in the line below.
PlayFile(@"c:\myaudio.wma");
}
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();
}
有是在http://msdn.microsoft.com/en-us/library/dd564582(VS.85).aspx
这篇关于我怎么能播放视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!