From 35ddf4a0120aeb6a8982098fd14df762e5a4b403 Mon Sep 17 00:00:00 2001 From: Michael Gordeev Date: Fri, 14 Sep 2018 18:10:54 +0300 Subject: [PATCH] #176: Done --- FoxTube/Controls/LiveCaptions.xaml.cs | 47 +++++++++++++++++---------- FoxTube/Controls/VideoPlayer.xaml.cs | 38 ++++++++++++++-------- FoxTube/Pages/MainPage.xaml.cs | 2 +- FoxTube/Pages/Search.xaml.cs | 6 ++-- 4 files changed, 59 insertions(+), 34 deletions(-) diff --git a/FoxTube/Controls/LiveCaptions.xaml.cs b/FoxTube/Controls/LiveCaptions.xaml.cs index 7231128..8bbd12b 100644 --- a/FoxTube/Controls/LiveCaptions.xaml.cs +++ b/FoxTube/Controls/LiveCaptions.xaml.cs @@ -23,6 +23,7 @@ namespace FoxTube.Controls public sealed partial class LiveCaptions : UserControl { public MediaElement Player { get; set; } + private bool isClosed = false; DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(10) }; List captions = new List(); Caption currentCaption = null; @@ -38,16 +39,17 @@ namespace FoxTube.Controls TimeSpan currentPosition = Player.Position; bool found = false; - captions.ForEach((x) => - { - if (Player.Position >= x.Start && Player.Position <= x.End) + if(!isClosed) + captions.ForEach((x) => { - currentCaption = x; - text.Text = currentCaption.Text; - Visibility = Visibility.Visible; - found = true; - } - }); + if (Player.Position >= x.Start && Player.Position <= x.End) + { + currentCaption = x; + text.Text = currentCaption.Text; + Visibility = Visibility.Visible; + found = true; + } + }); if (!found) { @@ -64,15 +66,16 @@ namespace FoxTube.Controls foreach (XmlElement i in doc["timedtext"]["body"].ChildNodes) captions.Add(new Caption(int.Parse(i.GetAttribute("t")), int.Parse(i.GetAttribute("d")), i.InnerText)); - captions.ForEach((x) => - { - if(Player.Position > x.Start && Player.Position < x.End) + if(!isClosed) + captions.ForEach((x) => { - currentCaption = x; - text.Text = currentCaption.Text; - Visibility = Visibility.Visible; - } - }); + if(Player.Position > x.Start && Player.Position < x.End) + { + currentCaption = x; + text.Text = currentCaption.Text; + Visibility = Visibility.Visible; + } + }); timer.Start(); } @@ -84,5 +87,15 @@ namespace FoxTube.Controls Visibility = Visibility.Collapsed; timer.Stop(); } + + public void Hide() + { + isClosed = true; + } + + public void Show() + { + isClosed = false; + } } } diff --git a/FoxTube/Controls/VideoPlayer.xaml.cs b/FoxTube/Controls/VideoPlayer.xaml.cs index 8d608df..7d50ab6 100644 --- a/FoxTube/Controls/VideoPlayer.xaml.cs +++ b/FoxTube/Controls/VideoPlayer.xaml.cs @@ -44,7 +44,19 @@ namespace FoxTube { public string videoId; - public bool miniView = false; + private bool miniview = false; + public bool MiniView + { + get { return miniview; } + set + { + miniview = value; + if (value) + captions.Hide(); + else + captions.Show(); + } + } private bool fullScreen = false; public bool pointerCaptured = false; @@ -244,7 +256,7 @@ namespace FoxTube void Elapsed() { controls.Visibility = Visibility.Collapsed; - if (!miniView) + if (!MiniView) touchCentral.Visibility = Visibility.Collapsed; if (pointerCaptured) { @@ -257,7 +269,7 @@ namespace FoxTube public void UpdateSize() { - if(miniView) + if(MiniView) { Height = Window.Current.Bounds.Height; Debug.WriteLine("Video player aspect ratio has been corrected."); @@ -318,7 +330,7 @@ namespace FoxTube void ShowControls() { controls.Visibility = Visibility.Visible; - if (miniView) + if (MiniView) seekIndicator.Visibility = Visibility.Visible; if (pointerCaptured) Window.Current.CoreWindow.PointerCursor = cursorBackup; @@ -477,10 +489,10 @@ namespace FoxTube private async void miniView_Click(object sender, RoutedEventArgs e) { ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar; - miniView = !miniView; - SetFullSize(this, miniView); + MiniView = !MiniView; + SetFullSize(this, MiniView); - if (miniView) + if (MiniView) { if (fullScreen) { @@ -606,7 +618,7 @@ namespace FoxTube Width = 432; Height = 243; - miniView = true; + MiniView = true; Methods.MainPage.MinimizeVideo(); mainControls.Visibility = Visibility.Collapsed; @@ -633,7 +645,7 @@ namespace FoxTube Width = double.NaN; Height = double.NaN; - miniView = false; + MiniView = false; Methods.MainPage.MaximizeVideo(); mainControls.Visibility = Visibility.Visible; @@ -671,19 +683,19 @@ namespace FoxTube private void playPauseArea_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) { - if (miniView && ApplicationView.GetForCurrentView().ViewMode == ApplicationViewMode.CompactOverlay) + if (MiniView && ApplicationView.GetForCurrentView().ViewMode == ApplicationViewMode.CompactOverlay) miniView_Click(this, null); - else if (miniView && ApplicationView.GetForCurrentView().ViewMode == ApplicationViewMode.Default) + else if (MiniView && ApplicationView.GetForCurrentView().ViewMode == ApplicationViewMode.Default) maximize_Click(this, null); else if (fullScreen) fullscreen_Click(this, null); - else if (!miniView && !fullScreen) + else if (!MiniView && !fullScreen) fullscreen_Click(this, null); } private void playPauseArea_Tapped(object sender, TappedRoutedEventArgs e) { - if (e.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse && !miniView) + if (e.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse && !MiniView) play_Click(this, null); } diff --git a/FoxTube/Pages/MainPage.xaml.cs b/FoxTube/Pages/MainPage.xaml.cs index 8b76f43..8a2c539 100644 --- a/FoxTube/Pages/MainPage.xaml.cs +++ b/FoxTube/Pages/MainPage.xaml.cs @@ -413,7 +413,7 @@ namespace FoxTube { nav.OpenPaneLength = 0; nav.CompactPaneLength = 0; - if ((videoPlaceholder.Content as VideoPage).player.miniView) + if ((videoPlaceholder.Content as VideoPage).player.MiniView) nav.Margin = new Thickness(0, -80, 0, 0); else nav.Margin = new Thickness(0, -91, 0, 0); diff --git a/FoxTube/Pages/Search.xaml.cs b/FoxTube/Pages/Search.xaml.cs index 6ec6459..0fe757c 100644 --- a/FoxTube/Pages/Search.xaml.cs +++ b/FoxTube/Pages/Search.xaml.cs @@ -96,7 +96,7 @@ namespace FoxTube { loading.Refresh(); - //try + try { Parameters = arg; request = SecretsVault.Service.Search.List("id,snippet"); @@ -159,14 +159,14 @@ namespace FoxTube loading.Close(); } - /*catch (System.Net.Http.HttpRequestException) + catch (System.Net.Http.HttpRequestException) { loading.Error("System.Net.Http.HttpRequestException", "Unable to connect to Google servers.", true); } catch (Exception e) { loading.Error(e.GetType().ToString(), e.Message); - }*/ + } } private void toggleFilters_Click(object sender, RoutedEventArgs e)