如何播放视频文件? [英] How can I play video files?
本文介绍了如何播放视频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我喜欢通过我的 C# 程序播放视频文件,例如 AVI.可以播放这样的视频文件吗?
I like to play video files, such as AVIs, through my C# program. Is it possible to play video files like that?
推荐答案
您应该能够使用 Media Player 控件播放媒体文件.
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
这篇关于如何播放视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文