1

i want to play video in c#. i searched related tutorial and i found this. i followed exactly the same but the video would not appear.

here is my code.

   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();
        }


    }
    }
}

i even tried to put a path of the video like this:

video = new Video("C:\\Users\\HDAdmin\\Desktop\\Example.avi");

but both of it will show the error like picture below. enter image description here

my question is, how i want to enable to view and play the video by using windows form application in c#?

p/s: i want to use Directx only and do not want to play the video in windows media player.

sara brown
  • 1,057
  • 8
  • 29
  • 46
  • Hope this help you.. http://stackoverflow.com/questions/2127445/how-can-i-play-video-files-using-c – Vinod Sep 17 '12 at 04:19
  • Did you refer this - http://stackoverflow.com/questions/4018924/mixed-mode-assembly-is-built-against-version-v1-1-4322? – Typist Sep 17 '12 at 04:46
  • i want the video to play by using DirectX and i dont want it to play in Windows Media Player. is there a way to solve this exception? – sara brown Sep 17 '12 at 05:43
  • Maybe [this question](http://stackoverflow.com/a/20441933/2263683) can help – Ghasem Jan 03 '16 at 07:59

0 Answers0