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 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のみを使用したいのですが、WindowsMediaPlayerでビデオを再生したくありません。