Click here to Skip to main content
16,019,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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):

C#
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)
            {
                // Use 32 bits library
                this.MyControl.MediaPlayer.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(Environment.CurrentDirectory, "libvlc-x86"));
            }
            else
            {
                // Use 64 bits library
                this.MyControl.MediaPlayer.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(Environment.CurrentDirectory, "libvlc-x64"));
            }

            var options = new string[]
            {
                // VLC options can be given here. Please refer to the VLC command line documentation.
                "--fullscreen"
            };

            this.MyControl.MediaPlayer.VlcMediaplayerOptions = options;

            // Load libvlc libraries and initializes stuff. It is important that the options (if you want to pass any) and lib directory are given before calling this method.
            this.MyControl.MediaPlayer.EndInit();
            this.MyControl.MediaPlayer.Play(playURL);
        }


And here is the code clip which calls the video window from the control window:

C#
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:

C#
YTPlayer YTwin = new YTPlayer();
YTwin.RaiseCustomEvent += new EventHandler<CustomEventArgs>(YTwin_RaiseCustomEvent);


with:

C#
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?
Posted
Updated 14-Oct-17 19:22pm

1 solution

OK... I figured it out! I was being thick. Hehehe

I suddenly realised (duh!) that "Select" is a method in the code behind YTPlayer, not a function in the API.

I just had to use:

C#
foreach (Window window in System.Windows.Application.Current.Windows)
                    {
                        if (window.GetType() == typeof(YTPlayer))
{
...
}


in YTControl, then move all of the Play/Pause/Stop commands in there, directly addressing the VLC API through the Control in the YTPlayer WPF window.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900