コード例 #1
0
        public async Task Play(MediaItem channel)
        {
            try
            {
                _opening = true;
                var plugin = _core.PluginLoader.GetPlugins <IVlcBinariesPlugin>().FirstOrDefault();
                if (plugin == null)
                {
                    throw new Exception("No VLC binaries plugin found");
                }
                var binariesPath = plugin.GetBinariesPath();

                _currentChannel = channel;

                IsPlaying    = true;
                HasSubtitles = false;
                IsPlaying    = false;

                CleanUp();
                _cts = new CancellationTokenSource();
                var cts = _cts;
                await SetupPipe(cts);

                if (cts.IsCancellationRequested)
                {
                    return;
                }
                if (_subProcess != null)
                {
                    HasNextChanged?.Invoke(this, false);
                    HasPreviousChanged?.Invoke(this, false);


                    var res = await _subProcess.Pipe.CallAsync("initialize", binariesPath, VlcParameters);

                    if (cts.IsCancellationRequested)
                    {
                        return;
                    }
                    //CaptureMousePanel.BringToFront();
                    if (res == null)
                    {
                        OnError(new Exception("Could not initialize"));
                        CleanUp();
                        return;
                    }

                    res = await _subProcess.Pipe.CallAsync("handle", pictureBox.Handle);

                    if (cts.IsCancellationRequested)
                    {
                        return;
                    }
                    if (res == null)
                    {
                        OnError(new Exception("Could not set handle"));
                        CleanUp();
                        return;
                    }

                    await SendToSubProcess("play", channel.GetMRL() + " " + channel.GetExtras());
                }
                else
                {
                    throw new Exception("Pipe not connected");
                }
            }
            catch (AggregateException ex)
            {
                if (ex.InnerException is ObjectDisposedException)
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                OnError(ex);
            }
            finally
            {
            }
        }