Please can anyone help? I've been scratching my head for days!
I'm trying to create an app which will play video on a second screen, but with the Play/Pause/Stop controls and the progress bar on the primary monitor.
I'm using the LibVLC library with the vlc.dotnet wrapper.
Please excuse any sloppy and copy/pasted code, but I'm still at the "Let's give it a go" stage at the moment.
Here's what I have for the code behind the second screen window (pretty much lifted directly from the vlc.dotnet code sample):
public void Select(String ytURL, String ytControl)
{
if (ytURL == "")
{
ytURL = "http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_h264.mov";
}
if (ytControl == "Play")
{
ytPlayVideo(ytURL);
}
else if (ytControl == "Stop")
{
}
else if (ytControl == "Pause")
{
}
}
private void ytPlayVideo(String playURL)
{
if (IntPtr.Size == 4)
{
this.MyControl.MediaPlayer.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(Environment.CurrentDirectory, "libvlc-x86"));
}
else
{
this.MyControl.MediaPlayer.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(Environment.CurrentDirectory, "libvlc-x64"));
}
var options = new string[]
{
"--fullscreen"
};
this.MyControl.MediaPlayer.VlcMediaplayerOptions = options;
this.MyControl.MediaPlayer.EndInit();
this.MyControl.MediaPlayer.Play(playURL);
}
And here is the code clip which calls the video window from the control window:
YTPlayer YTwin = new YTPlayer();
int s2 = Screen.AllScreens.Count();
if (s2 > 1)
{
Screen s1 = Screen.AllScreens[1];
System.Drawing.Rectangle r1 = s1.WorkingArea;
YTwin.WindowState = System.Windows.WindowState.Normal;
YTwin.WindowStartupLocation = WindowStartupLocation.Manual;
YTwin.Top = r1.Top;
YTwin.Left = r1.Left;
YTwin.Show();
}
YTwin.Select("", "Play");
So far so good. That plays the video perfectly, and I can even pass different video links to it when the new window is instantiated, but I can't for the life of me work out how to pass commands to the VLC WPF control on the second screen once it's already running for Pause, Stop, etc., or pass the data back from the video window to the controller window for the progress bar.
It has to be done with two separate windows, as the secondary screen needs to be maximised, whilst the control surface on the primary needs to be re-sizeable.
What I have tried:
I've checked out quite a few threads on here and other fora about how to address WPF controls in one window from another, and how to pass variables between classes.
For example, raising a custom event and exposing it at instantiation:
YTPlayer YTwin = new YTPlayer();
YTwin.RaiseCustomEvent += new EventHandler<CustomEventArgs>(YTwin_RaiseCustomEvent);
with:
public event EventHandler<CustomEventArgs> RaiseCustomEvent;
Problem is that whatever I try like that throws an error with the vlc.dotnet "Select" and says it doesn't exist.
I need to be able to call YTPlayer.Select() from YTControl window while YTPlayer window is open and running, without instantiating a new instance of YTPlayer.
Any ideas?