Archived
1
0

Video player basics

This commit is contained in:
Michael Gordeev
2018-05-06 13:15:48 +03:00
parent 810c8fc464
commit 0dff7636fd
5 changed files with 253 additions and 5 deletions
+7
View File
@@ -148,6 +148,9 @@
<Compile Include="VideoList.xaml.cs"> <Compile Include="VideoList.xaml.cs">
<DependentUpon>VideoList.xaml</DependentUpon> <DependentUpon>VideoList.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="VideoPlayer.xaml.cs">
<DependentUpon>VideoPlayer.xaml</DependentUpon>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<AppxManifest Include="Package.appxmanifest"> <AppxManifest Include="Package.appxmanifest">
@@ -284,6 +287,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="VideoPlayer.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Google.Apis"> <PackageReference Include="Google.Apis">
+5 -3
View File
@@ -55,6 +55,7 @@ namespace FoxTube
settings.Values.Add("moblieWarning", false); settings.Values.Add("moblieWarning", false);
settings.Values.Add("videoAutoplay", true); settings.Values.Add("videoAutoplay", true);
settings.Values.Add("volume", 100);
} }
content.Navigate(typeof(Home)); content.Navigate(typeof(Home));
} }
@@ -360,7 +361,8 @@ namespace FoxTube
private void searchButton_Click(object sender, RoutedEventArgs e) private void searchButton_Click(object sender, RoutedEventArgs e)
{ {
StartSearch(searchField.Text); if(searchField.Text != "")
StartSearch(searchField.Text);
} }
private async void StartSearch(string keyword) private async void StartSearch(string keyword)
@@ -369,7 +371,7 @@ namespace FoxTube
YouTubeService ytService = new YouTubeService(new BaseClientService.Initializer() YouTubeService ytService = new YouTubeService(new BaseClientService.Initializer()
{ {
ApiKey = "INSERT_API_HERE", ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0",
ApplicationName = this.GetType().ToString() ApplicationName = this.GetType().ToString()
}); });
@@ -390,7 +392,7 @@ namespace FoxTube
private void searchField_KeyUp(object sender, KeyRoutedEventArgs e) private void searchField_KeyUp(object sender, KeyRoutedEventArgs e)
{ {
if (e.Key == Windows.System.VirtualKey.Enter) if (e.Key == Windows.System.VirtualKey.Enter)
StartSearch(searchField.Text); searchButton_Click(this, null);
} }
} }
} }
+2 -1
View File
@@ -13,7 +13,8 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<StackPanel Height="600" Background="Black"/> <!--<StackPanel Height="600" Background="Black"/>-->
<local:VideoPlayer/>
<ScrollViewer> <ScrollViewer>
<StackPanel Margin="10"> <StackPanel Margin="10">
<TextBlock Text="Video title this is very biiiiig title. It's amazingly big. OLOLOLOLOLO!!!!!!)))))). 1234567890. ABCD" FontSize="25" TextWrapping="WrapWholeWords" HorizontalTextAlignment="Start"/> <TextBlock Text="Video title this is very biiiiig title. It's amazingly big. OLOLOLOLOLO!!!!!!)))))). 1234567890. ABCD" FontSize="25" TextWrapping="WrapWholeWords" HorizontalTextAlignment="Start"/>
+124
View File
@@ -0,0 +1,124 @@
<UserControl
x:Class="FoxTube.VideoPlayer"
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"
d:DesignHeight="1080"
d:DesignWidth="1920"
SizeChanged="UserControl_SizeChanged"
Tapped="UserControl_Tapped"
PointerMoved="UserControl_PointerMoved">
<Grid>
<StackPanel Background="White"/>
<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="Collapsed">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Button Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE099;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Minimize"/>
<TextBlock Grid.Column="1" Text="This is Video title" Foreground="White" VerticalAlignment="Center" TextWrapping="WrapWholeWords" FontSize="20" Margin="10,0,0,0" MaxLines="1" ToolTipService.ToolTip="Title"/>
<StackPanel Orientation="Horizontal" Grid.Column="2">
<Button Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xEC15;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Cast to device"/>
<Button Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE2B3;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Picture-in-picture mode"/>
</StackPanel>
</Grid>
</Grid>
<Grid Grid.Row="2">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition/>
<ColumnDefinition Width="252"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<Button Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE768;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Play"/>
<Button 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"/>
</StackPanel>
<Popup Grid.Column="0" Margin="100,-200,50,0" IsOpen="False" IsLightDismissEnabled="True" Name="volumePane">
<StackPanel Background="#7F000000" Width="50" Height="200">
<Slider Orientation="Vertical" HorizontalAlignment="Center" Height="135" Margin="5,10,10,5" Name="volume" ValueChanged="volume_ValueChanged"/>
<Button Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE995;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Mute" Name="muteBtn" Click="muteBtn_Click"/>
</StackPanel>
</Popup>
<TextBlock Foreground="White" Text="18:28" VerticalAlignment="Bottom" Grid.Column="1" HorizontalAlignment="Left" Margin="10,0,10,0" ToolTipService.ToolTip="Time elapsed"/>
<TextBlock Foreground="White" Text="18:28" VerticalAlignment="Bottom" Grid.Column="1" HorizontalAlignment="Right" Margin="10,0,10,0" ToolTipService.ToolTip="Time remaining"/>
<Slider Grid.Column="1" VerticalAlignment="Top" Margin="10,0,10,0" ToolTipService.ToolTip="Seek" IsThumbToolTipEnabled="False"/>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<Button Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xED3C;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Skip back for 10 seconds"/>
<Button Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xED3D;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Skip forward for 30 seconds"/>
<Line Stroke="White" StrokeThickness="2" Y1="5" Y2="45"/>
<Button Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE190;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Subtitles" Name="openSubs" Click="openSubs_Click"/>
<Button Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE713;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Video quality" Name="openSets" Click="openSets_Click"/>
<Button Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE740;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Full screen"/>
</StackPanel>
<Popup Grid.Column="2" Margin="0,-100,50,0" IsOpen="False" IsLightDismissEnabled="True" Name="subsPane">
<StackPanel Background="#7F000000" Width="252" Height="100" Padding="10">
<ToggleSwitch Name="subsSwitch" Foreground="White" OffContent="Show subtitles" OnContent="Show subtitles"/>
<ComboBox Width="232" PlaceholderText="No subtitles are available"/>
</StackPanel>
</Popup>
<Popup Grid.Column="2" IsOpen="False" Margin="0,-73,0,0" IsLightDismissEnabled="True" Name="qualityPane">
<StackPanel Background="#7F000000" Width="252" Padding="10">
<TextBlock Text="Quality" Foreground="White"/>
<Line X1="0" X2="232" Stroke="White" StrokeThickness="2"/>
<ComboBox Width="232">
<ComboBoxItem Content="Auto"/>
<ComboBoxItem Content="4320p"/>
<ComboBoxItem Content="2160p"/>
<ComboBoxItem Content="1440p"/>
<ComboBoxItem Content="1080p60"/>
<ComboBoxItem Content="1080p30"/>
<ComboBoxItem Content="720p60"/>
<ComboBoxItem Content="720p30"/>
<ComboBoxItem Content="480p"/>
<ComboBoxItem Content="360p"/>
<ComboBoxItem Content="240p"/>
<ComboBoxItem Content="144p"/>
</ComboBox>
</StackPanel>
</Popup>
</Grid>
</Grid>
</Grid>
</Grid>
</UserControl>
+114
View File
@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Timers;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI.Core;
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 User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace FoxTube
{
public sealed partial class VideoPlayer : UserControl
{
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
Timer t = new Timer();
public VideoPlayer()
{
this.InitializeComponent();
volume.Value = (double)settings.Values["volume"];
t.Elapsed += T_Elapsed;
UserControl_Tapped(this, null);
}
private async void T_Elapsed(object sender, ElapsedEventArgs e)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, Elapsed);
}
void Elapsed()
{
volumePane.IsOpen = false;
qualityPane.IsOpen = false;
controls.Visibility = Visibility.Collapsed;
t.Stop();
}
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
Height = e.NewSize.Width / 16 * 9;
}
private void openVolume_Click(object sender, RoutedEventArgs e)
{
volumePane.IsOpen = true;
}
private void volume_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
double v = volume.Value;
if (v == 0)
muteBtn.Content = openVolume.Content = "";
else if (v <= 25 && v > 0)
muteBtn.Content = openVolume.Content = "";
else if (v <= 50 && v > 25)
muteBtn.Content = openVolume.Content = "";
else if (v <= 75 && v > 50)
muteBtn.Content = openVolume.Content = "";
else if (v > 75)
muteBtn.Content = openVolume.Content = "";
settings.Values["volume"] = volume.Value;
}
private void openSets_Click(object sender, RoutedEventArgs e)
{
qualityPane.IsOpen = true;
}
private void openSubs_Click(object sender, RoutedEventArgs e)
{
subsPane.IsOpen = true;
subsSwitch.IsOn = !subsSwitch.IsOn;
}
private void muteBtn_Click(object sender, RoutedEventArgs e)
{
if(volume.Value != 0)
{
double v = (double)settings.Values["volume"];
volume.Value = 0;
settings.Values["volume"] = v;
}
else volume.Value = (double)settings.Values["volume"];
}
private void UserControl_Tapped(object sender, TappedRoutedEventArgs e)
{
controls.Visibility = Visibility.Visible;
t.Interval = 5000;
t.Stop();
t.Start();
}
private void UserControl_PointerMoved(object sender, PointerRoutedEventArgs e)
{
controls.Visibility = Visibility.Visible;
t.Interval = 3000;
t.Stop();
t.Start();
}
}
}