I want to make a C# Windows Forms App That displays a pen which changes into a pineapple when you click it, turns into an apple when you click the pineapple and the back into a pen, which, when you click, starts a music video. What doesn't work for me is the video, which I do not want to display in a Windows Media Player plainly because I don't like it. Here is the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.DirectX.DirectSound;
using Microsoft.DirectX.AudioVideoPlayback;
using Microsoft.DirectX;
namespace Picture_Button
{
public partial class Form1 : Form
{
Video video = new Video("C:\\Users\\Pushkin\\Desktop\\PPAP.mp4");
private int clicks = 0;
public Form1()
{
InitializeComponent();
video.Owner = this;
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
clicks++;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
switch (clicks)
{
case 0: pictureBox1.Image = Properties.Resources.Pineapple; break;
case 1: pictureBox1.Image = Properties.Resources.Apple; break;
case 2: pictureBox1.Image = Properties.Resources.Pen; break;
case 3: video.Play(); break;
case 4: video.Dispose(); break;
}
}
}
}
And literally nothing happens, the program simply freezes as if it were into an infinite loop here:
Video video = new Video("C:\\Users\\Pushkin\\Desktop\\PPAP.mp4");
Nothing shows up. Any ideas what the problem is?
EDIT: I'm trying to handle the Ending event so I can make the app exit when the video ends and somehow I managed to get this exception:
System.NullReferenceException occurred
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Microsoft.DirectX.AudioVideoPlayback
StackTrace:
at VideoWndProc(HWND__* hWnd, UInt32 uMsg, UInt32 wParam, Int32 lParam)
InnerException:
By adding this code:
video.Ending += new System.EventHandler(this.Video_Ending);
//some code
private void Video_Ending(object sender, EventArgs e)
{
//throw new NotImplementedException();
video.Dispose();
Application.Exit();
}