使用c#中的窗体应用程序,使用DirectX而不是Windows media player播放视频文件
我想用c#播放视频。我搜索了相关的教程,找到了。我遵循了完全相同的方法,但视频没有出现 这是我的密码使用c#中的窗体应用程序,使用DirectX而不是Windows media player播放视频文件,c#,video,C#,Video,我想用c#播放视频。我搜索了相关的教程,找到了。我遵循了完全相同的方法,但视频没有出现 这是我的密码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Micros
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
Video video;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// store the original size of the panel
int width = panel1.Width;
int height = panel1.Height;
// load the selected video file
//video = new Video("C:\\Users\\HDAdmin\\Desktop\\Example.avi");
video = new Video(openFileDialog1.FileName);
// set the panel as the video object’s owner
video.Owner = panel1;
// stop the video
video.Stop();
// resize the video to the size original size of the panel
panel1.Size = new Size(width, height);
try
{
video.Audio.Volume = 100;
}
catch { }
}
}
private void button2_Click(object sender, EventArgs e)
{
if (video.State != StateFlags.Running)
{
video.Play();
}
}
private void button3_Click(object sender, EventArgs e)
{
if (video.State == StateFlags.Running)
{
video.Pause();
}
}
private void button4_Click(object sender, EventArgs e)
{
if (video.State != StateFlags.Stopped)
{
video.Stop();
}
}
}
}
我甚至试着把视频的路径放在下面:
video = new Video("C:\\Users\\HDAdmin\\Desktop\\Example.avi");
但这两个都会显示错误,如下图所示。
我的问题是,如何在c#中使用windows窗体应用程序来查看和播放视频
p/s:我只想使用Directx,不想在windows media player中播放视频。希望这对您有所帮助。。您是否引用了此-?我希望使用DirectX播放视频,但不希望在Windows Media Player中播放。有办法解决这个异常吗?也许能帮上忙