Archived
1
0

Video player development 4

This commit is contained in:
Michael Gordeev
2018-06-19 00:08:00 +03:00
parent 5c164332de
commit ca36c495dd
13 changed files with 255 additions and 84 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ namespace FoxTube
// When the navigation stack isn't restored navigate to the first page, // When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation // configuring the new page by passing required information as a navigation
// parameter // parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments); rootFrame.Navigate(typeof(SubLayer), e.Arguments);
} }
// Ensure the current window is active // Ensure the current window is active
Window.Current.Activate(); Window.Current.Activate();
+1 -3
View File
@@ -59,9 +59,7 @@ namespace FoxTube
private void Button_Click(object sender, RoutedEventArgs e) private void Button_Click(object sender, RoutedEventArgs e)
{ {
Frame root = Window.Current.Content as Frame; SecretsVault.SubLayer.Main.GoToChannel(channelId);
MainPage main = root.Content as MainPage;
main.GoToChannel(channelId);
} }
} }
} }
+7
View File
@@ -129,6 +129,9 @@
<Compile Include="Settings.xaml.cs"> <Compile Include="Settings.xaml.cs">
<DependentUpon>Settings.xaml</DependentUpon> <DependentUpon>Settings.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="SubLayer.xaml.cs">
<DependentUpon>SubLayer.xaml</DependentUpon>
</Compile>
<Compile Include="Translate.xaml.cs"> <Compile Include="Translate.xaml.cs">
<DependentUpon>Translate.xaml</DependentUpon> <DependentUpon>Translate.xaml</DependentUpon>
</Compile> </Compile>
@@ -255,6 +258,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="SubLayer.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Translate.xaml"> <Page Include="Translate.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
-30
View File
@@ -542,36 +542,6 @@ namespace FoxTube
} }
} }
public static string NormalizeDuration(string code)
{
Debug.WriteLine(string.Format("Source string: '{0}'", code));
string temp = code.Trim('P', 'T', 'S');
Debug.WriteLine(string.Format("Trimmed string: '{0}'", temp));
temp = temp.Replace('H', '|');
temp = temp.Replace('M', '|');
if (temp.StartsWith('|'))
temp.TrimStart('|');
if (temp.EndsWith('|'))
temp.TrimEnd('|');
Debug.WriteLine(string.Format("End string: '{0}'", temp));
string[] arr = temp.Split('|');
Debug.WriteLine(string.Format("Array length: {0}", arr.Length));
foreach (string str in arr)
Debug.WriteLine(str);
switch(arr.Length)
{
case 3:
return new TimeSpan(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1]), Convert.ToInt32(arr[2])).ToString();
case 2:
return new TimeSpan(0, Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1])).ToString();
case 1:
return new TimeSpan(0, 0, Convert.ToInt32(arr[0])).ToString();
default:
return "";
}
}
private void searchSuggestionsList_SelectionChanged(object sender, SelectionChangedEventArgs e) private void searchSuggestionsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
if(e.AddedItems.Count > 0) if(e.AddedItems.Count > 0)
+12
View File
@@ -7,6 +7,8 @@ using Google.Apis.Auth.OAuth2;
using Google.Apis.Services; using Google.Apis.Services;
using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3;
using Google.Apis.Auth.OAuth2.Flows; using Google.Apis.Auth.OAuth2.Flows;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace FoxTube namespace FoxTube
{ {
@@ -96,5 +98,15 @@ namespace FoxTube
#region Authorization service functions #region Authorization service functions
#endregion #endregion
#region Simplifying stuff
public static SubLayer SubLayer
{
get
{
return (Window.Current.Content as Frame).Content as SubLayer;
}
}
#endregion
} }
} }
+1
View File
@@ -35,6 +35,7 @@
<TextBlock Text="Playback" FontSize="22"/> <TextBlock Text="Playback" FontSize="22"/>
<ComboBox Margin="0,0,0,10" Width="250" Header="Default video playback quality" Name="quality" SelectionChanged="quality_SelectionChanged"> <ComboBox Margin="0,0,0,10" Width="250" Header="Default video playback quality" Name="quality" SelectionChanged="quality_SelectionChanged">
<ComboBoxItem Content="Auto"/> <ComboBoxItem Content="Auto"/>
<ComboBoxItem Content="2160p"/>
<ComboBoxItem Content="1080p"/> <ComboBoxItem Content="1080p"/>
<ComboBoxItem Content="720p"/> <ComboBoxItem Content="720p"/>
<ComboBoxItem Content="480p"/> <ComboBoxItem Content="480p"/>
+12
View File
@@ -0,0 +1,12 @@
<Page
x:Class="FoxTube.SubLayer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FoxTube"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="Black">
<Grid Name="grid"/>
</Page>
+60
View File
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace FoxTube
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class SubLayer : Page
{
public MainPage Main = new MainPage();
public Frame Fullscreen = new Frame();
Video initialParent;
public SubLayer()
{
this.InitializeComponent();
grid.Children.Add(Main);
grid.Children.Add(Fullscreen);
}
public void EnterFullScreen(VideoPlayer element, Video initParent)
{
initialParent = initParent;
if(grid.Children.Contains(element))
{
grid.Children.Remove(element);
initialParent.SetPlayerBack();
initialParent = null;
}
else
grid.Children.Add(element);
/*Fullscreen.Content = element;
Fullscreen.Visibility = Visibility.Visible;*/
}
public void ExitFullScreen()
{
grid.Children.RemoveAt(1);
initialParent.SetPlayerBack();
/*Fullscreen.Content = null;
Fullscreen.Visibility = Visibility.Collapsed;*/
}
}
}
+19 -3
View File
@@ -30,6 +30,8 @@ namespace FoxTube
string videoId; string videoId;
Google.Apis.YouTube.v3.Data.Video item; Google.Apis.YouTube.v3.Data.Video item;
VideoPlayer player;
public Video() public Video()
{ {
this.InitializeComponent(); this.InitializeComponent();
@@ -45,11 +47,11 @@ namespace FoxTube
item = response.Items[0]; item = response.Items[0];
title.Text = item.Snippet.Title; title.Text = item.Snippet.Title;
views.Text = item.Statistics.ViewCount + " views"; /*views.Text = item.Statistics.ViewCount + " views";
dislikes.Text = item.Statistics.DislikeCount.ToString(); dislikes.Text = item.Statistics.DislikeCount.ToString();
likes.Text = item.Statistics.LikeCount.ToString(); likes.Text = item.Statistics.LikeCount.ToString();
Debug.WriteLine((double)item.Statistics.DislikeCount / (double)(item.Statistics.DislikeCount + item.Statistics.LikeCount) * 250); Debug.WriteLine((double)item.Statistics.DislikeCount / (double)(item.Statistics.DislikeCount + item.Statistics.LikeCount) * 250);
dislikeLine.X2 = (double)item.Statistics.DislikeCount / (double)(item.Statistics.DislikeCount + item.Statistics.LikeCount) * 250; dislikeLine.X2 = (double)item.Statistics.DislikeCount / (double)(item.Statistics.DislikeCount + item.Statistics.LikeCount) * 250;*/
description.Text = item.Snippet.Description; description.Text = item.Snippet.Description;
ChannelsResource.ListRequest request1 = SecretsVault.YoutubeService.Channels.List("snippet,contentDetails,statistics"); ChannelsResource.ListRequest request1 = SecretsVault.YoutubeService.Channels.List("snippet,contentDetails,statistics");
@@ -62,7 +64,21 @@ namespace FoxTube
channelName.Text = item.Snippet.ChannelTitle; channelName.Text = item.Snippet.ChannelTitle;
subscribers.Text = item1.Statistics.SubscriberCount + " subscribers"; subscribers.Text = item1.Statistics.SubscriberCount + " subscribers";
mainContent.Children.Add(new VideoPlayer(id, item1.Snippet.Thumbnails.Medium.Url)); player = new VideoPlayer(id, item1.Snippet.Thumbnails.Medium.Url);
player.SetFullSize += Player_SetFullSize;
mainContent.Children.Add(player);
}
private void Player_SetFullSize(object sender, EventArgs e)
{
mainContent.Children.Clear();
SecretsVault.SubLayer.EnterFullScreen(player, this);
}
public void SetPlayerBack()
{
mainContent.Children.Add(player);
} }
private void gotoChannel_Click(object sender, RoutedEventArgs e) private void gotoChannel_Click(object sender, RoutedEventArgs e)
+1 -1
View File
@@ -73,7 +73,7 @@ namespace FoxTube
private void Button_Click(object sender, RoutedEventArgs e) private void Button_Click(object sender, RoutedEventArgs e)
{ {
((Window.Current.Content as Frame).Content as MainPage).GoToVideo(videoId); SecretsVault.SubLayer.Main.GoToVideo(videoId);
} }
} }
} }
+2 -2
View File
@@ -70,12 +70,12 @@ namespace FoxTube
private void channelLink_Click(object sender, RoutedEventArgs e) private void channelLink_Click(object sender, RoutedEventArgs e)
{ {
((Window.Current.Content as Frame).Content as MainPage).GoToChannel(item.Snippet.ChannelId); SecretsVault.SubLayer.Main.GoToChannel(item.Snippet.ChannelId);
} }
private void Button_Click(object sender, RoutedEventArgs e) private void Button_Click(object sender, RoutedEventArgs e)
{ {
((Window.Current.Content as Frame).Content as MainPage).GoToVideo(videoId); SecretsVault.SubLayer.Main.GoToVideo(videoId);
} }
} }
} }
+21 -8
View File
@@ -20,9 +20,9 @@
<TextBox Name="subtitleCapture" Visibility="Collapsed" Text="This is subtitle capture" Background="#99000000" VerticalAlignment="Bottom" HorizontalAlignment="Center" Foreground="White" FontSize="24" Padding="10" Margin="0,0,0,100"/> <TextBox Name="subtitleCapture" Visibility="Collapsed" Text="This is subtitle capture" Background="#99000000" VerticalAlignment="Bottom" HorizontalAlignment="Center" Foreground="White" FontSize="24" Padding="10" Margin="0,0,0,100"/>
<Grid Name="controls" Visibility="Visible"> <Grid Name="controls" Visibility="Visible">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="auto"/> <RowDefinition Height="50"/>
<RowDefinition/> <RowDefinition/>
<RowDefinition Height="auto"/> <RowDefinition Height="50"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Grid.Row="0" Name="header" Background="#7F000000"> <Grid Grid.Row="0" Name="header" Background="#7F000000">
<!--<Grid.Background> <!--<Grid.Background>
@@ -34,21 +34,34 @@
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Visibility="Collapsed" Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xEC15;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Cast to device"/> <Button Visibility="Collapsed" Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xEC15;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Cast to device"/>
<Button Name="miniView" Click="miniView_Click" Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE2B3;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Compact view mode"/> <Button Name="miniView" Click="miniView_Click" Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE2B3;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Compact view mode" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
<Button Visibility="Collapsed" VerticalAlignment="Top" HorizontalAlignment="Right" Name="miniViewExit" Grid.Row="1" Click="miniView_Click" Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE2B3;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Compact view mode"/> <Button Visibility="Collapsed" Margin="0,35,0,0" VerticalAlignment="Top" HorizontalAlignment="Right" Name="miniViewExit" Grid.Row="1" Click="miniView_Click" Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE2B4;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Compact view mode"/>
<StackPanel Name="touchCentral" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed"> <StackPanel Name="touchCentral" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed">
<Button VerticalAlignment="Center" Content="&#xED3C;" FontFamily="Segoe MDL2 Assets" Background="Transparent" FontSize="40" Foreground="WhiteSmoke" Name="touchBack10" Click="back10_Click"/> <Button VerticalAlignment="Center" Content="&#xED3C;" FontFamily="Segoe MDL2 Assets" Background="Transparent" FontSize="40" Foreground="WhiteSmoke" Name="touchBack10" Click="back10_Click"/>
<Button VerticalAlignment="Center" Content="&#xE102;" FontFamily="Segoe MDL2 Assets" Background="Transparent" FontSize="100" Foreground="WhiteSmoke" Name="touchPlay" Click="play_Click"/> <Button VerticalAlignment="Center" Content="&#xE102;" FontFamily="Segoe MDL2 Assets" Background="Transparent" FontSize="100" Foreground="WhiteSmoke" Name="touchPlay" Click="play_Click"/>
<Button VerticalAlignment="Center" Content="&#xED3D;" FontFamily="Segoe MDL2 Assets" Background="Transparent" FontSize="40" Foreground="WhiteSmoke" Name="touchFwd30" Click="fwd30_Click"/> <Button VerticalAlignment="Center" Content="&#xED3D;" FontFamily="Segoe MDL2 Assets" Background="Transparent" FontSize="40" Foreground="WhiteSmoke" Name="touchFwd30" Click="fwd30_Click"/>
</StackPanel> </StackPanel>
<Button Name="skipAd" Visibility="Collapsed" Grid.Row="1" HorizontalAlignment="Right" Foreground="White" VerticalAlignment="Bottom" Padding="10" BorderBrush="Black" BorderThickness="2" Background="#7E000000"> <Button Name="skipAd" Visibility="Collapsed" Margin="0,0,0,25" Grid.Row="1" HorizontalAlignment="Right" Foreground="White" VerticalAlignment="Bottom" Padding="10" BorderBrush="Black" BorderThickness="2" Background="#7E000000">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock FontFamily="Segoe MDL2 Assets" FontSize="30" Margin="0,0,10,0" Text="&#xE101;" VerticalAlignment="Center"/> <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="30" Margin="0,0,10,0" Text="&#xE101;" VerticalAlignment="Center"/>
<TextBlock Text="Skip ad" FontSize="30" TextWrapping="WrapWholeWords" MaxWidth="250"/> <TextBlock Text="Skip ad" FontSize="30" TextWrapping="WrapWholeWords" MaxWidth="250"/>
</StackPanel> </StackPanel>
</Button> </Button>
<StackPanel Name="schedulePanel" Visibility="Collapsed" VerticalAlignment="Bottom" HorizontalAlignment="Right" Grid.Row="1" BorderBrush="Black" BorderThickness="2" Background="#7E000000" Padding="10" Margin="25" Orientation="Horizontal">
<TextBlock FontFamily="Segoe MDL2 Assets" FontSize="30" Margin="0,0,10,0" Foreground="White" Text="&#xE704;"/>
<StackPanel>
<TextBlock Foreground="White" FontWeight="Bold" Text="Stream hasn't started yet"/>
<TextBlock Name="scheduleHeader" Foreground="White" Text="Stream schedule:"/>
<TextBlock Name="scheduleStart" Foreground="White" Text="Start time: 18-Jun-18 12:12:12 AM"/>
<TextBlock Foreground="White" Name="scheduleEnd" Text="End time: 18-Jun-18 12:12:12 AM"/>
<TextBlock Name="countdownHeader" Foreground="White" FontWeight="Bold" Text="Stream will be started in:" Margin="0,10,0,0"/>
<TextBlock Foreground="White" Name="streamCountdown" FontWeight="SemiBold" FontSize="20" Text="1:10:31:48"/>
<ToggleButton Content="Enable notification" Foreground="White" Margin="5"/>
</StackPanel>
</StackPanel>
<Grid Grid.Row="2" Name="mainControls" Background="#7F000000"> <Grid Grid.Row="2" Name="mainControls" Background="#7F000000">
<!--<Grid.Background> <!--<Grid.Background>
<AcrylicBrush TintColor="Black" TintOpacity="0.795" BackgroundSource="Backdrop" AlwaysUseFallback="False" Opacity="0.8"/> <AcrylicBrush TintColor="Black" TintOpacity="0.795" BackgroundSource="Backdrop" AlwaysUseFallback="False" Opacity="0.8"/>
@@ -62,7 +75,7 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Button Click="play_Click" Name="play" Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE768;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Play"/> <Button Click="play_Click" Name="play" Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE768;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Play"/>
<Button Name="next" Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE101;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Next video"/> <Button Name="next" Click="next_Click" Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE101;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Next video"/>
<Button Name="openVolume" Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE995;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Volume" Click="openVolume_Click"/> <Button Name="openVolume" Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE995;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Volume" Click="openVolume_Click"/>
</StackPanel> </StackPanel>
<Popup Grid.Column="0" Margin="100,-200,50,0" IsOpen="False" IsLightDismissEnabled="True" Name="volumePane"> <Popup Grid.Column="0" Margin="100,-200,50,0" IsOpen="False" IsLightDismissEnabled="True" Name="volumePane">
@@ -115,7 +128,7 @@
<StackPanel Background="#7F000000" Width="252" Padding="10"> <StackPanel Background="#7F000000" Width="252" Padding="10">
<TextBlock Text="Quality" Foreground="White"/> <TextBlock Text="Quality" Foreground="White"/>
<Line X1="0" X2="232" Stroke="White" StrokeThickness="2"/> <Line X1="0" X2="232" Stroke="White" StrokeThickness="2"/>
<ComboBox Width="232" Name="quality" SelectionChanged="quality_SelectionChanged"> <ComboBox Width="232" Name="quality" SelectionChanged="quality_SelectionChanged" SelectedIndex="0">
<ComboBoxItem Content="Auto"/> <ComboBoxItem Content="Auto"/>
<ComboBoxItem Content="2160P"/> <ComboBoxItem Content="2160P"/>
<ComboBoxItem Content="1080p"/> <ComboBoxItem Content="1080p"/>
@@ -123,7 +136,7 @@
<ComboBoxItem Content="480p"/> <ComboBoxItem Content="480p"/>
<ComboBoxItem Content="360p"/> <ComboBoxItem Content="360p"/>
<ComboBoxItem Content="240p"/> <ComboBoxItem Content="240p"/>
<ComboBoxItem Content="144p" Visibility="Collapsed"/> <ComboBoxItem Content="144p"/>
</ComboBox> </ComboBox>
</StackPanel> </StackPanel>
</Popup> </Popup>
+116 -34
View File
@@ -27,6 +27,7 @@ using Windows.Media;
using Windows.Storage.Streams; using Windows.Storage.Streams;
using Windows.UI.ViewManagement; using Windows.UI.ViewManagement;
using System.Xml; using System.Xml;
using Windows.ApplicationModel.Core;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
@@ -40,7 +41,10 @@ namespace FoxTube
private bool fullScreen = false; private bool fullScreen = false;
private bool pointerCaptured = false; private bool pointerCaptured = false;
UIElement rootBackup; public event EventHandler SetFullSize;
public event EventHandler NextClicked;
CoreCursor cursorBackup;
TimeSpan elapsed; TimeSpan elapsed;
TimeSpan remaining; TimeSpan remaining;
@@ -55,11 +59,11 @@ namespace FoxTube
YouTubeQuality.QualityHigh, YouTubeQuality.QualityHigh,
YouTubeQuality.Quality2160P, YouTubeQuality.Quality2160P,
YouTubeQuality.Quality1080P, YouTubeQuality.Quality1080P,
YouTubeQuality.Quality270P, YouTubeQuality.Quality720P,
YouTubeQuality.Quality480P, YouTubeQuality.Quality480P,
YouTubeQuality.Quality360P, YouTubeQuality.Quality360P,
YouTubeQuality.Quality240P, YouTubeQuality.Quality240P,
YouTubeQuality.Quality144P, YouTubeQuality.Quality144P
}; };
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings; ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
@@ -68,7 +72,13 @@ namespace FoxTube
Interval = 5000, Interval = 5000,
Enabled = true Enabled = true
}; };
Timer seekTimer = new Timer() { Interval = 1000 }; Timer seekTimer = new Timer()
{
Interval = 1000,
Enabled = true
};
Timer countdown;
public VideoPlayer(string id, string channelAvatar) public VideoPlayer(string id, string channelAvatar)
{ {
@@ -83,14 +93,15 @@ namespace FoxTube
t.Elapsed += T_Elapsed; t.Elapsed += T_Elapsed;
seekTimer.Elapsed += SeekTimer_Elapsed; seekTimer.Elapsed += SeekTimer_Elapsed;
CheckQualityAvailability(id);
Initialize(id, channelAvatar); Initialize(id, channelAvatar);
} }
public async void Initialize(string id, string channelAvatar) public async void Initialize(string id, string channelAvatar)
{ {
CheckQualityAvailability(id);
videoId = id; videoId = id;
VideosResource.ListRequest request = SecretsVault.YoutubeService.Videos.List("snippet,contentDetails,statistics"); VideosResource.ListRequest request = SecretsVault.YoutubeService.Videos.List("snippet,contentDetails,statistics,liveStreamingDetails");
request.Id = id; request.Id = id;
VideoListResponse response = await request.ExecuteAsync(); VideoListResponse response = await request.ExecuteAsync();
@@ -116,9 +127,38 @@ namespace FoxTube
touchCentral.Visibility = Visibility.Collapsed; touchCentral.Visibility = Visibility.Collapsed;
miniView.Visibility = Visibility.Collapsed; miniView.Visibility = Visibility.Collapsed;
controls.Visibility = Visibility.Visible; controls.Visibility = Visibility.Visible;
schedulePanel.Visibility = Visibility.Visible;
if (item.LiveStreamingDetails.ScheduledStartTime != null)
{
scheduleStart.Text = "Start time: " + item.LiveStreamingDetails.ScheduledStartTime;
countdown = new Timer()
{
Interval = 1000,
Enabled = true
};
countdown.Elapsed += Countdown_Elapsed;
}
else
{
scheduleHeader.Visibility = Visibility.Collapsed;
scheduleStart.Visibility = Visibility.Collapsed;
countdownHeader.Visibility = Visibility.Collapsed;
streamCountdown.Visibility = Visibility.Collapsed;
}
if (item.LiveStreamingDetails.ScheduledEndTime != null)
scheduleEnd.Text = "End time: " + item.LiveStreamingDetails.ScheduledEndTime;
else scheduleEnd.Visibility = Visibility.Collapsed;
try { videoSource.PosterSource = new BitmapImage(new Uri(item.Snippet.Thumbnails.Maxres.Url)); }
catch { }
title.Text = item.Snippet.Title;
return;
} }
videoSource.PosterSource = new BitmapImage(new Uri(item.Snippet.Thumbnails.Maxres.Url)); try { videoSource.PosterSource = new BitmapImage(new Uri(item.Snippet.Thumbnails.Maxres.Url)); }
catch { }
title.Text = item.Snippet.Title; title.Text = item.Snippet.Title;
YouTubeUri uri = await YouTube.GetVideoUriAsync(id, qualities[quality.SelectedIndex]); YouTubeUri uri = await YouTube.GetVideoUriAsync(id, qualities[quality.SelectedIndex]);
@@ -133,8 +173,6 @@ namespace FoxTube
elapsedTime.Text = string.Format("{0}{1:00}:{2:00}", elapsed.Hours == 0 ? "" : elapsed.Hours + ":", elapsed.Minutes, elapsed.Seconds); elapsedTime.Text = string.Format("{0}{1:00}:{2:00}", elapsed.Hours == 0 ? "" : elapsed.Hours + ":", elapsed.Minutes, elapsed.Seconds);
remainingTime.Text = string.Format("{0}{1:00}:{2:00}", remaining.Hours == 0 ? "" : remaining.Hours + ":", remaining.Minutes, remaining.Seconds); remainingTime.Text = string.Format("{0}{1:00}:{2:00}", remaining.Hours == 0 ? "" : remaining.Hours + ":", remaining.Minutes, remaining.Seconds);
systemControls.IsNextEnabled = true; systemControls.IsNextEnabled = true;
systemControls.IsPauseEnabled = true; systemControls.IsPauseEnabled = true;
systemControls.IsPlayEnabled = true; systemControls.IsPlayEnabled = true;
@@ -148,23 +186,41 @@ namespace FoxTube
systemControls.ButtonPressed += SystemControls_Engaged; systemControls.ButtonPressed += SystemControls_Engaged;
} }
void CheckQualityAvailability(string id) private async void Countdown_Elapsed(object sender, ElapsedEventArgs e)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, CountdownElapsed);
}
void CountdownElapsed()
{
TimeSpan span = (TimeSpan)(item.LiveStreamingDetails.ScheduledStartTime - DateTime.Now);
if (span.TotalMilliseconds > 0)
streamCountdown.Text = string.Format("{0}{1:00}:{2:00}:{3:00}", span.Days != 0 ? span.Days + ":" : "", span.Hours, span.Minutes, span.Seconds);
else
{
streamCountdown.Text = "Stream will be started shortly...";
countdownHeader.Visibility = Visibility.Collapsed;
}
}
async void CheckQualityAvailability(string id)
{ {
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{
try try
{ {
YouTube.GetVideoUriAsync(id, qualities[i]); YouTubeUri uri = await YouTube.GetVideoUriAsync(id, qualities[i]);
Debug.WriteLine(qualities[i].ToString() + ": Checked");
Debug.WriteLine("Result URI: " + uri.Uri);
} }
catch catch
{ {
(quality.Items[i] as ComboBoxItem).Visibility = Visibility.Collapsed; (quality.Items[i] as ComboBoxItem).Visibility = Visibility.Collapsed;
Debug.WriteLine(qualities[i].ToString() + ": Error");
} }
}
int k = (int)settings.Values["quality"] + int k = (int)settings.Values["quality"];
(int)settings.Values["quality"] > 0 ? 1 : 0;
if ((quality.Items[k] as ComboBoxItem).Visibility == Visibility.Collapsed) if ((quality.Items[k] as ComboBoxItem).Visibility == Visibility.Collapsed)
for (int i = 0; i < 8; i++) for (int i = 7; i >= 0; i--)
{ {
if ((quality.Items[i] as ComboBoxItem).Visibility == Visibility.Visible) if ((quality.Items[i] as ComboBoxItem).Visibility == Visibility.Visible)
{ {
@@ -207,25 +263,28 @@ namespace FoxTube
seek.Value = videoSource.Position.TotalSeconds; seek.Value = videoSource.Position.TotalSeconds;
} }
async void Elapsed() void Elapsed()
{ {
if(!volumePane.IsOpen && !qualityPane.IsOpen && item.Snippet.LiveBroadcastContent != "upcoming") if(!volumePane.IsOpen && !qualityPane.IsOpen && item.Snippet.LiveBroadcastContent != "upcoming")
{ {
await controls.Fade().StartAsync(); //await controls.Fade().StartAsync();
volumePane.IsOpen = false; volumePane.IsOpen = false;
qualityPane.IsOpen = false; qualityPane.IsOpen = false;
controls.Visibility = Visibility.Collapsed; controls.Visibility = Visibility.Collapsed;
if(!miniViewed) if(!miniViewed)
touchCentral.Visibility = Visibility.Collapsed; touchCentral.Visibility = Visibility.Collapsed;
if (pointerCaptured) /*if (pointerCaptured)
{
cursorBackup = Window.Current.CoreWindow.PointerCursor;
Window.Current.CoreWindow.PointerCursor = null; Window.Current.CoreWindow.PointerCursor = null;
}*/
t.Stop(); t.Stop();
} }
} }
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
{ {
Height = e.NewSize.Width / 16 * 9; //Height = e.NewSize.Width / 16 * 9;
} }
private void openVolume_Click(object sender, RoutedEventArgs e) private void openVolume_Click(object sender, RoutedEventArgs e)
@@ -249,7 +308,7 @@ namespace FoxTube
settings.Values["volume"] = volume.Value; settings.Values["volume"] = volume.Value;
videoSource.Volume = volume.Value; videoSource.Volume = volume.Value * 0.01;
} }
private void openSets_Click(object sender, RoutedEventArgs e) private void openSets_Click(object sender, RoutedEventArgs e)
@@ -297,8 +356,10 @@ namespace FoxTube
if(controls.Visibility == Visibility.Collapsed) if(controls.Visibility == Visibility.Collapsed)
{ {
controls.Visibility = Visibility.Visible; controls.Visibility = Visibility.Visible;
await controls.Fade(value: 1).StartAsync(); //await controls.Fade(value: 1).StartAsync();
} }
/*if (pointerCaptured)
Window.Current.CoreWindow.PointerCursor = cursorBackup;*/
t.Stop(); t.Stop();
t.Start(); t.Start();
} }
@@ -325,21 +386,23 @@ namespace FoxTube
private void fullscreen_Click(object sender, RoutedEventArgs e) private void fullscreen_Click(object sender, RoutedEventArgs e)
{ {
TimeSpan elapsedBakcup = new TimeSpan(videoSource.Position.Ticks);
if (fullScreen) if (fullScreen)
{ {
Window.Current.Content = rootBackup; //SecretsVault.SubLayer.ExitFullScreen();
SetFullSize.Invoke(this, null);
ApplicationView.GetForCurrentView().ExitFullScreenMode(); ApplicationView.GetForCurrentView().ExitFullScreenMode();
fullscreen.Content = "";
fullScreen = false; fullScreen = false;
} }
else else
{ {
rootBackup = Window.Current.Content; //SecretsVault.SubLayer.EnterFullScreen(this);
Window.Current.Content = this;
fullScreen = ApplicationView.GetForCurrentView().TryEnterFullScreenMode(); fullScreen = ApplicationView.GetForCurrentView().TryEnterFullScreenMode();
} SetFullSize.Invoke(this, null);
if ((string)fullscreen.Content == "")
fullscreen.Content = ""; fullscreen.Content = "";
else fullscreen.Content = ""; }
videoSource.Position = elapsedBakcup;
} }
private void play_Click(object sender, RoutedEventArgs e) private void play_Click(object sender, RoutedEventArgs e)
@@ -356,28 +419,39 @@ namespace FoxTube
{ {
case MediaElementState.Buffering: case MediaElementState.Buffering:
bufferingBar.Visibility = Visibility.Visible; bufferingBar.Visibility = Visibility.Visible;
seek.IsEnabled = false; seek.IsEnabled = false;
play.IsEnabled = false; play.IsEnabled = false;
seekTimer.Stop(); touchPlay.IsEnabled = false;
play.Content = "";
touchPlay.Content = "";
break; break;
case MediaElementState.Paused: case MediaElementState.Paused:
bufferingBar.Visibility = Visibility.Collapsed; bufferingBar.Visibility = Visibility.Collapsed;
seek.IsEnabled = true;
play.IsEnabled = true;
touchPlay.IsEnabled = true;
play.Content = ""; play.Content = "";
touchPlay.Content = ""; touchPlay.Content = "";
seekTimer.Stop();
break; break;
case MediaElementState.Playing: case MediaElementState.Playing:
bufferingBar.Visibility = Visibility.Collapsed; bufferingBar.Visibility = Visibility.Collapsed;
seek.IsEnabled = true;
play.IsEnabled = true;
touchPlay.IsEnabled = true;
play.Content = ""; play.Content = "";
touchPlay.Content = ""; touchPlay.Content = "";
seekTimer.Start();
break; break;
default: default:
bufferingBar.Visibility = Visibility.Collapsed; bufferingBar.Visibility = Visibility.Collapsed;
seekTimer.Stop();
break; break;
} }
} }
@@ -389,12 +463,15 @@ namespace FoxTube
private async void miniView_Click(object sender, RoutedEventArgs e) private async void miniView_Click(object sender, RoutedEventArgs e)
{ {
TimeSpan elapsedBakcup = new TimeSpan(videoSource.Position.Ticks);
if (fullScreen) if (fullScreen)
{ {
ApplicationView.GetForCurrentView().ExitFullScreenMode(); ApplicationView.GetForCurrentView().ExitFullScreenMode();
fullScreen = false;
fullscreen.Content = ""; fullscreen.Content = "";
fullScreen = false;
} }
else
SetFullSize.Invoke(this, null);
if (!miniViewed) if (!miniViewed)
{ {
@@ -405,7 +482,6 @@ namespace FoxTube
header.Visibility = Visibility.Collapsed; header.Visibility = Visibility.Collapsed;
touchBack10.FontSize = touchFwd30.FontSize = 20; touchBack10.FontSize = touchFwd30.FontSize = 20;
touchPlay.FontSize = 50; touchPlay.FontSize = 50;
} }
else else
{ {
@@ -417,6 +493,7 @@ namespace FoxTube
touchBack10.FontSize = touchFwd30.FontSize = 40; touchBack10.FontSize = touchFwd30.FontSize = 40;
touchPlay.FontSize = 100; touchPlay.FontSize = 100;
} }
videoSource.Position = elapsedBakcup;
} }
private void seek_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) private void seek_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
@@ -457,5 +534,10 @@ namespace FoxTube
if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse) if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
pointerCaptured = true; pointerCaptured = true;
} }
private void next_Click(object sender, RoutedEventArgs e)
{
NextClicked.Invoke(this, null);
}
} }
} }