Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
+ Added release info in video player #3
Browse files Browse the repository at this point in the history
  • Loading branch information
trueromanus committed Feb 9, 2019
1 parent 9b463f2 commit 8cb393c
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 75 deletions.
169 changes: 110 additions & 59 deletions src/Anilibria/Pages/OnlinePlayer/OnlinePlayerView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PauseIcon">
<EasingDoubleKeyFrame KeyTime="0" Value="0" />
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value=".6" />
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value=".8" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Name="HidePause">
Expand All @@ -35,7 +35,7 @@
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PauseIcon">
<EasingDoubleKeyFrame KeyTime="0" Value=".6" />
<EasingDoubleKeyFrame KeyTime="0" Value=".8" />
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
Expand Down Expand Up @@ -351,8 +351,28 @@
Width="{StaticResource IconSize}"
Height="{StaticResource IconSize}"
Source="/Assets/Icons/humburger.svg"
/>
/>
</Button>
<TextBlock
x:Name="CurrentVideoPositionPanel"
RelativePanel.RightOf="SidebarButton"
FontSize="16"
Foreground="White"
VerticalAlignment="Center"
Margin="6 12 0 0">
<Run
Text="{Binding DisplayPosition}"
/>
<Run
Text="{Binding DisplayPositionPercent}"
/>
<Run
Text="/"
/>
<Run
Text="{Binding DisplayDuration}"
/>
</TextBlock>
<Button
x:Name="VolumeButton"
RelativePanel.LeftOf="SettingsButton"
Expand Down Expand Up @@ -485,28 +505,6 @@
</Button>
</RelativePanel>
</Border>
<StackPanel
Grid.Row="0"
Grid.Column="1"
Grid.ColumnSpan="2"
Orientation="Vertical">
<Grid HorizontalAlignment="Right">
<Rectangle
Fill="LightGray"
Opacity=".4">
</Rectangle>
<TextBlock
Visibility="Collapsed"
x:Name="TitleLabel"
FontSize="30"
MaxLines="2"
TextWrapping="Wrap"
TextTrimming="CharacterEllipsis"
Foreground="LightGray">
(Восхождение героя щита)Tate no Yuusha no Nariagari
</TextBlock>
</Grid>
</StackPanel>
<Grid
Grid.RowSpan="3"
Grid.ColumnSpan="3"
Expand Down Expand Up @@ -534,31 +532,78 @@
</Viewbox>
</Grid>
<StackPanel
x:Name="CurrentReleaseInfo"
Visibility="Collapsed"
Grid.Row="2"
Grid.Column="2">
<Grid HorizontalAlignment="Right">
<Rectangle
Fill="LightGray"
Opacity=".4"
/>
<StackPanel Margin="2 0 2 0">
<TextBlock
x:Name="CurrentPositionLabel"
FontSize="30"
Foreground="White"
HorizontalAlignment="Right">
<Run Text="{Binding DisplayPosition}"></Run>
<Run Text="{Binding DisplayPositionPercent}"></Run>
</TextBlock>
<TextBlock
x:Name="DurationLabel"
FontSize="30"
Foreground="White"
HorizontalAlignment="Right"
Text="{Binding DisplayDuration}"
<Border
BorderBrush="#881919"
BorderThickness="2"
HorizontalAlignment="Right">
<Grid>
<Rectangle
Fill="White"
/>
</StackPanel>
</Grid>
<StackPanel Margin="2 0 2 0" Orientation="Horizontal">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel
Grid.Row="0"
Orientation="Vertical">
<TextBlock
x:Name="CurrentReleaseTitle"
FontSize="20"
Foreground="#b32121"
HorizontalAlignment="Right"
TextWrapping="WrapWholeWords"
TextTrimming="CharacterEllipsis"
MaxLines="5"
Text="{Binding SelectedRelease.Title}">
</TextBlock>
<TextBlock
x:Name="CurrentVideoTitle"
FontSize="20"
Foreground="Black"
TextTrimming="CharacterEllipsis"
HorizontalAlignment="Right"
Text="{Binding SelectedOnlineVideo.Title}">
</TextBlock>
</StackPanel>
<StackPanel
Grid.Row="1"
Orientation="Vertical">
<TextBlock
x:Name="CurrentVideoPosition"
FontSize="20"
Foreground="Black"
HorizontalAlignment="Right"
VerticalAlignment="Bottom">
<Run Text="{Binding DisplayPosition}"></Run>
<Run Text="{Binding DisplayPositionPercent}"></Run>
</TextBlock>
<TextBlock
x:Name="CurrentVideoDuration"
FontSize="20"
Foreground="Black"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Text="{Binding DisplayDuration}"
/>
</StackPanel>
</Grid>
<Image
x:Name="PosterImage"
Margin="3 3 1 3"
Source="{Binding SelectedRelease.Poster}"
Stretch="Uniform"
Height="200"
/>
</StackPanel>
</Grid>
</Border>
</StackPanel>
</Grid>
<VisualStateManager.VisualStateGroups>
Expand All @@ -570,9 +615,10 @@
<VisualState.Setters>
<Setter Target="PauseIconViewbox.Width" Value="245" />
<Setter Target="PauseIconViewbox.Height" Value="245" />
<Setter Target="TitleLabel.FontSize" Value="30" />
<Setter Target="CurrentPositionLabel.FontSize" Value="30" />
<Setter Target="DurationLabel.FontSize" Value="30" />
<Setter Target="CurrentReleaseTitle.FontSize" Value="20" />
<Setter Target="CurrentVideoTitle.FontSize" Value="20" />
<Setter Target="CurrentVideoPosition.FontSize" Value="20" />
<Setter Target="CurrentVideoDuration.FontSize" Value="20" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Wide">
Expand All @@ -582,9 +628,10 @@
<VisualState.Setters>
<Setter Target="PauseIconViewbox.Width" Value="200"/>
<Setter Target="PauseIconViewbox.Height" Value="200"/>
<Setter Target="TitleLabel.FontSize" Value="24" />
<Setter Target="CurrentPositionLabel.FontSize" Value="24" />
<Setter Target="DurationLabel.FontSize" Value="24" />
<Setter Target="CurrentReleaseTitle.FontSize" Value="16" />
<Setter Target="CurrentVideoTitle.FontSize" Value="16" />
<Setter Target="CurrentVideoPosition.FontSize" Value="16" />
<Setter Target="CurrentVideoDuration.FontSize" Value="16" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Square">
Expand All @@ -594,9 +641,11 @@
<VisualState.Setters>
<Setter Target="PauseIconViewbox.Width" Value="100"/>
<Setter Target="PauseIconViewbox.Height" Value="100"/>
<Setter Target="TitleLabel.FontSize" Value="18" />
<Setter Target="CurrentPositionLabel.FontSize" Value="18" />
<Setter Target="DurationLabel.FontSize" Value="18" />
<Setter Target="CurrentReleaseTitle.FontSize" Value="14" />
<Setter Target="CurrentVideoTitle.FontSize" Value="14" />
<Setter Target="CurrentVideoPosition.FontSize" Value="14" />
<Setter Target="CurrentVideoDuration.FontSize" Value="14" />
<Setter Target="PosterImage.Height" Value="160" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Snapped">
Expand All @@ -606,9 +655,11 @@
<VisualState.Setters>
<Setter Target="PauseIconViewbox.Width" Value="50"/>
<Setter Target="PauseIconViewbox.Height" Value="50"/>
<Setter Target="TitleLabel.FontSize" Value="14" />
<Setter Target="CurrentPositionLabel.FontSize" Value="14" />
<Setter Target="DurationLabel.FontSize" Value="14" />
<Setter Target="CurrentReleaseTitle.FontSize" Value="12" />
<Setter Target="CurrentVideoTitle.FontSize" Value="12" />
<Setter Target="CurrentVideoPosition.FontSize" Value="12" />
<Setter Target="CurrentVideoDuration.FontSize" Value="12" />
<Setter Target="PosterImage.Height" Value="140" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
Expand Down
27 changes: 20 additions & 7 deletions src/Anilibria/Pages/OnlinePlayer/OnlinePlayerView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,35 @@ private void StopTimer () {
if ( m_DispatherTimer.IsEnabled ) m_DispatherTimer.Stop ();
}

private void ChangePlaybackHandler ( PlaybackState state ) {
private void ChangePlaybackHandler ( PlaybackState state , bool needAnimation = true ) {
switch ( state ) {
case PlaybackState.Stop:
if ( OnlinePlayer.MediaPlayer.PlaybackSession.PlaybackState == MediaPlaybackState.Playing ) OnlinePlayer.MediaPlayer.Pause ();
OnlinePlayer.MediaPlayer.PlaybackSession.Position = TimeSpan.FromSeconds ( 0 );
break;
case PlaybackState.Pause:
if ( OnlinePlayer.MediaPlayer.PlaybackSession.CanPause ) {
RunShowPauseAnimation ();
if ( needAnimation ) {
RunShowPauseAnimation ();
}
else {
PauseIcon.Opacity = .8;
}
OnlinePlayer.MediaPlayer.Pause ();
CurrentReleaseInfo.Visibility = Visibility.Visible;
}
break;
case PlaybackState.Play:
if ( OnlinePlayer.MediaPlayer.PlaybackSession.PlaybackState == MediaPlaybackState.Paused ) RunHidePauseAnimation ();
if ( OnlinePlayer.MediaPlayer.PlaybackSession.PlaybackState == MediaPlaybackState.Paused ) {
if ( needAnimation ) {
RunHidePauseAnimation ();
}
else {
PauseIcon.Opacity = 0;
}
}
if ( OnlinePlayer.MediaPlayer.PlaybackSession.PlaybackState != MediaPlaybackState.Playing ) OnlinePlayer.MediaPlayer.Play ();
CurrentReleaseInfo.Visibility = Visibility.Collapsed;
break;
default: throw new NotSupportedException ( $"State {state} not supporting." );
}
Expand All @@ -114,6 +128,7 @@ await Dispatcher.RunAsync (
() => {
m_Duration = OnlinePlayer.MediaPlayer.PlaybackSession.NaturalDuration;
m_ViewModel.MediaOpened ( true , m_Duration );
PauseIcon.Opacity = 0;
}
);
}
Expand All @@ -130,12 +145,10 @@ private async void OnlinePlayer_Tapped ( object sender , TappedRoutedEventArgs e

switch ( OnlinePlayer.MediaPlayer.PlaybackSession.PlaybackState ) {
case MediaPlaybackState.Playing:
RunShowPauseAnimation ();
OnlinePlayer.MediaPlayer.Pause ();
ChangePlaybackHandler ( PlaybackState.Pause , needAnimation: true );
break;
case MediaPlaybackState.Paused:
RunHidePauseAnimation ();
OnlinePlayer.MediaPlayer.Play ();
ChangePlaybackHandler ( PlaybackState.Play , needAnimation: true );
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Anilibria/Pages/OnlinePlayer/OnlinePlayerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void RefreshPosition ( TimeSpan timeSpan ) {
/// <param name="parameter">Parameter.</param>
public void NavigateTo ( object parameter ) {
if ( parameter == null ) {
if ( VideoSource != null ) ChangePlayback ( PlaybackState.Play );
if ( VideoSource != null ) ChangePlayback ( PlaybackState.Play , false );
}
else {
Releases = parameter as IEnumerable<ReleaseModel>;
Expand All @@ -157,7 +157,7 @@ public void NavigateTo ( object parameter ) {
/// End navigate to page.
/// </summary>
public void NavigateFrom () {
if ( VideoSource != null ) ChangePlayback ( PlaybackState.Pause );
if ( VideoSource != null ) ChangePlayback ( PlaybackState.Pause , false );
}

/// <summary>
Expand Down Expand Up @@ -308,7 +308,7 @@ public Action<double> ChangeVolumeHandler
/// <summary>
/// Change playback state (pause, play or stop).
/// </summary>
public Action<PlaybackState> ChangePlayback
public Action<PlaybackState , bool> ChangePlayback
{
get;
set;
Expand Down
1 change: 1 addition & 0 deletions src/Anilibria/Pages/OnlinePlayer/PlaybackState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/// Playback state.
/// </summary>
public enum PlaybackState {

Stop = 0,

Pause = 1,
Expand Down
22 changes: 16 additions & 6 deletions src/Anilibria/Pages/OnlinePlayer/VideoTimeFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;

namespace Anilibria.Pages.OnlinePlayer {

Expand All @@ -9,24 +10,33 @@ public static class VideoTimeFormatter {

private static string FormattingMinutes ( int value ) {
if ( value == 0 ) return "";
if ( value == 1 ) return $"{value} минута";
if ( value >= 2 && value <= 4 ) return $"{value} минуты";

var lastDigit = Convert.ToInt32 ( value.ToString ().Last ().ToString() );

if ( lastDigit == 1 ) return $"{value} минута";
if ( lastDigit >= 2 && lastDigit <= 4 ) return $"{value} минуты";

return $"{value} минут";
}

private static string FormattingSeconds ( int value ) {
if ( value == 0 ) return "";
if ( value == 1 ) return $"{value} секунда";
if ( value >= 2 && value <= 4 ) return $"{value} секунды";

var lastDigit = Convert.ToInt32 ( value.ToString ().Last ().ToString () );

if ( lastDigit == 1 ) return $"{value} секунда";
if ( lastDigit >= 2 && lastDigit <= 4 ) return $"{value} секунды";

return $"{value} секунд";
}

private static string FormattingHours ( int value ) {
if ( value == 0 ) return "";
if ( value == 1 ) return $"{value} час";
if ( value >= 2 && value <= 4 ) return $"{value} часа";

var lastDigit = Convert.ToInt32 ( value.ToString ().Last ().ToString () );

if ( lastDigit == 1 ) return $"{value} час";
if ( lastDigit >= 2 && lastDigit <= 4 ) return $"{value} часа";

return $"{value} часов";
}
Expand Down

0 comments on commit 8cb393c

Please sign in to comment.