protected override async void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            try
            {
                if (e.Args.Length == 0)
                {
                    Shutdown();
                    return;
                }
                //MessageBox.Show("edw");
                var  source       = new TaskCompletionSource <object>();
                var  handleSource = new TaskCompletionSource <object>();
                bool exited       = false;
                client = new TcpProcessInteropClient(int.Parse(e.Args[0]));
                client.Register("initialize", payload =>
                {
                    //MessageBox.Show("init");
                    if (exited)
                    {
                        return(null);
                    }

                    source     = new TaskCompletionSource <object>();
                    var path   = payload[0].ToString();
                    _arguments = payload[1].ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    bool init = false;
                    if (!File.Exists(Path.Combine(path, "libvlc.dll")))
                    {
                        Current.Shutdown();
                        return(null);
                    }

                    var pluginsPath              = Path.Combine(path, "plugins");
                    VlcContext.LibVlcDllsPath    = path;
                    VlcContext.LibVlcPluginsPath = pluginsPath;

                    VlcContext.StartupOptions.IgnoreConfig                 = true;
                    VlcContext.StartupOptions.LogOptions.LogInFile         = false;
                    VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false;
                    VlcContext.StartupOptions.LogOptions.Verbosity         = VlcLogVerbosities.None;
                    VlcContext.StartupOptions.AddOption("--input-timeshift-granularity=0");
                    VlcContext.StartupOptions.AddOption("--auto-preparse");
                    VlcContext.StartupOptions.AddOption("--album-art=0");
                    //VlcContext.StartupOptions.AddOption("--overlay=1");
                    //VlcContext.StartupOptions.AddOption("--deinterlace=-1");
                    //VlcContext.StartupOptions.AddOption("--network-caching=1500");


                    foreach (var arg in _arguments)
                    {
                        try
                        {
                            //MessageBox.Show(arg);
                            VlcContext.StartupOptions.AddOption(arg.ToString());
                        }
                        catch
                        {
                        }
                    }
                    try
                    {
                        VlcContext.Initialize();
                        init = true;
                    }
                    catch (Exception)
                    {
                        //MessageBox.Show(ex.Message);
                        Application.Current.Shutdown();
                    }
                    source.SetResult(null);
                    return(init ? new object[] { } : null);
                });
                client.Register("shutdown", async args =>
                {
                    exited = true;
                    if (source != null)
                    {
                        await source.Task;
                    }
                    await Dispatcher.BeginInvoke(new Action(() =>
                    {
                        if (_vlc != null)
                        {
                            _vlc.Stop();
                            _vlc.Dispose();
                        }
                        if (VlcContext.IsInitialized)
                        {
                            VlcContext.CloseAll();
                        }
                        Shutdown();
                    }));
                    return(new object[] { });
                });
                client.Register("handle", async args =>
                {
                    if (exited)
                    {
                        return(null);
                    }
                    await Dispatcher.BeginInvoke(new Action(() =>
                    {
                        if (_vlc != null)
                        {
                            _vlc.Dispose();
                        }
                        _vlc = new VlcControlHeadless((IntPtr)long.Parse(args[0].ToString()));
                        SetupPlayer();
                    }));
                    return(new object[] { });
                });
                client.Subscribe("play", args =>
                {
                    if (!string.IsNullOrEmpty(args[0].ToString()))
                    {
                        _duration = TimeSpan.FromSeconds(0);
                        var split = args[0].ToString().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        //var split2 = _arguments.ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        _currentMedia = new LocationMedia(split[0]);
                        SetHandlersForMedia(_currentMedia);

                        _vlc.Media = _currentMedia;
                        if (split.Length > 1)
                        {
                            foreach (var extra in split.Skip(1))
                            {
                                //MessageBox.Show(extra);
                                _currentMedia.AddOption(extra);
                            }
                        }
                    }
                    else
                    {
                        _vlc.Play();
                    }
                });
                client.Subscribe("position", args =>
                {
                    _vlc.Position = float.Parse(args[0].ToString());
                });
                client.Subscribe("pause", args =>
                {
                    _vlc.Pause();
                });
                client.Subscribe("next", args =>
                {
                    try
                    {
                        if (_currentMedia as LocationMedia == null)
                        {
                            return;
                        }
                        var subitems = (_currentMedia as LocationMedia).SubItems;
                        var cmedia   = _vlc.Media as LocationMedia;
                        if (cmedia == null)
                        {
                            return;
                        }
                        var index = subitems.IndexOf(subitems.First(m => m.MRL == cmedia.MRL));
                        if (subitems.Count > 0 && index < subitems.Count - 1)
                        {
                            _vlc.Next();
                        }
                    }
                    catch
                    {
                    }
                });
                client.Subscribe("previous", args =>
                {
                    try
                    {
                        if (_currentMedia as LocationMedia == null)
                        {
                            return;
                        }
                        var subitems = (_currentMedia as LocationMedia).SubItems;
                        var cmedia   = _vlc.Media as LocationMedia;
                        if (cmedia == null)
                        {
                            return;
                        }
                        var index = subitems.IndexOf(subitems.First(m => m.MRL == cmedia.MRL));
                        if (subitems.Count > 0 && index > 0)
                        {
                            _vlc.Previous();
                        }
                    }
                    catch
                    {
                    }
                });
                client.Subscribe("next-subtitle", args =>
                {
                    if (_vlc.VideoProperties.SpuDescription.Next != null && _vlc.VideoProperties.SpuDescription.Next.Id != _vlc.VideoProperties.CurrentSpuIndex)
                    {
                        _vlc.VideoProperties.CurrentSpuIndex = _vlc.VideoProperties.SpuDescription.Next.Id;
                    }
                    else
                    {
                        _vlc.VideoProperties.CurrentSpuIndex = -1;
                    }
                    _vlc.VideoProperties.SetSubtitleFile(null);
                });

                client.Subscribe("set-subtitles", args =>
                {
                    var title = args[0].ToString();
                    if (title == "-1" && _subtitles?.Any(kv => kv.Key.ToString() == title) == true)
                    {
                        _vlc.VideoProperties.CurrentSpuIndex = -1;
                        _vlc.VideoProperties.SetSubtitleFile(null);
                    }
                    else if (_subtitles.Count > 1)
                    {
                        _vlc.VideoProperties.CurrentSpuIndex = _subtitles.Keys.Skip(1).First();
                        _vlc.VideoProperties.SetSubtitleFile(null);
                    }
                });

                if (await client.ConnectAsync(5000))
                {
                    client.Start();
                }
                else
                {
                    Shutdown();
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
            }
        }