コード例 #1
0
        public override void Dispose()
        {
            innerAnalyser?.Dispose();
            Controller?.RemoveMessage(this, KEY_THUNDER);
            innerAnalyser = null;
            Controller?.RemoveAnalyser(this);

            GC.Collect();
        }
コード例 #2
0
        public override async Task SetURLAsync(string url)
        {
            URL = Converters.UrlConverter.TranslateURLThunder(url);
            Controller?.UpdateMessage(this, KEY_THUNDER, new PlainTextMessage(
                                          AppResources.GetString("ThunderLinkDetected")));
            innerAnalyser?.Dispose();
            innerAnalyser = null;
            innerAnalyser = Converters.UrlConverter.GetAnalyser(URL);
            if (innerAnalyser == null)
            {
                Controller?.UpdateMessage(this, KEY_THUNDER, new PlainTextMessage(
                                              AppResources.GetString("ThunderLinkDetectedButFailed")));
                return;
            }

            Controller?.RegistAnalyser(this, innerAnalyser);
            innerAnalyser.BindVisualController(Controller);
            await innerAnalyser.SetURLAsync(URL);
        }
コード例 #3
0
        public override async Task SetURLAsync(string url)
        {
            try
            {
                id = YoutubeClient.ParseVideoId(url);
                var client = new YoutubeClient();
                Controller?.UpdateMessage(this, KEY_YOUTUBE,
                                          new PlainTextMessage(AppResources.GetString("YouTubeLinkDetectedButWaiting")));
                video = await client.GetVideoAsync(id);

                infos = await client.GetVideoMediaStreamInfosAsync(id);

                if (infos.Muxed.Count > 0)
                {
                    Controller?.SetComboBoxLayoutVisibility(this, true);
                }
                else
                {
                    throw new Exception();
                }

                Controller?.UpdateMessage(this, KEY_YOUTUBE,
                                          new PlainTextMessage(
                                              AppResources.GetString("YouTubeLinkDetectedButWaiting")
                                              + " - " +
                                              video.Title
                                              ));

                foreach (var info in infos.Muxed)
                {
                    PlainTextComboBoxData data = new PlainTextComboBoxData();
                    data.Text = info.VideoQuality.ToString() + " - " + info.VideoEncoding.ToString();
                    Controller?.AddComboBoxItem(this, data);
                }

                Controller?.SetComboBoxSelectionChangedListener(this,
                                                                async(item) => {
                    innerAnalyser?.Dispose();
                    string target = GetURLFromInfos(item.Text);
                    if (target != null)
                    {
                        innerAnalyser = Converters.UrlConverter.GetAnalyser(target);
                        if (innerAnalyser != null)
                        {
                            URL = target;
                            innerAnalyser.BindVisualController(Controller);
                            Controller?.RegistAnalyser(this, innerAnalyser);
                            await innerAnalyser.SetURLAsync(target);
                        }
                    }
                }
                                                                );
            }
            catch (Exception)
            {
                Controller?.UpdateMessage(this, KEY_YOUTUBE,
                                          new PlainTextMessage(
                                              AppResources.GetString("YouTubeLinkDetectedButFailed")
                                              ));
                Controller?.SetComboBoxLayoutVisibility(this, false);
            }
        }