Hey all I am trying to add a function method to VideoControl.cs so that I can call it from my Form1.cs button click. The code I am using is from a Github here.
Right now, in order to start a movie, I have to right-click inside the videoControl1 on the form and select Load from the ToolStripMenu.
Doing that it goes into the VideoControl.cs loadFileToolStripMenuItem_Click function:
private void loadFileToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog
{
Title = "Browse Video Files",
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = "ts",
Filter = "All Media Files|*.MP4",
FilterIndex = 2,
RestoreDirectory = true,
ReadOnlyChecked = true,
ShowReadOnly = true
};
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
m_fileName = openFileDialog1.FileName;
m_lastPlayedIsFile = true;
Play(out string outMessage);
if (pCallback != null)
{
foreach (IVideoControl p in pCallback)
{
p.NotifyPlay(m_fileName, true);
}
}
}
}
So when I create a public function in VideoControl.cs like this so that I can just pass the video path to it without the need to select it form the browser select popup:
public static void testingVid(string theVideo)
{
m_fileName = theVideo;
m_lastPlayedIsFile = true;
Play(out string outMessage);
if (pCallback != null)
{
foreach (IVideoControl p in pCallback)
{
p.NotifyPlay(m_fileName, true);
}
}
}
And I am calling that like this from the Form1.cs:
VideoControl.testingVid(@"C:\Users\Admin\Videos\a_test_video.mp4");
I get the error on VideoControl.testingVid saying:
Error CS0120 An object reference is required for the non-static field, method, or property 'VideoControl.testingVid(string)'
When I create an instance of the class and invoke the method like this:
VideoControl VC = new VideoControl();
VC.testingVid(@"C:\Users\Admin\Videos\a_test_video.mp4");
It works (no errors) but it does not perform the same as if I did the right-click menu option. No error but it never plays.
Stepping through the code for both methods they both have the same data at the end (the video path and p.NotifyPlay(m_fileName, true); value of 1 in the loop).
What am I missing here?

