Skip to content

Commit

Permalink
Make the progress text consistent in player view
Browse files Browse the repository at this point in the history
  • Loading branch information
cjw1115 committed Jul 21, 2020
1 parent 0cff65a commit f3d6db3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
3 changes: 2 additions & 1 deletion AilianBT/AilianBT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\PlayStatusConverter.cs" />
<Compile Include="Converters\TimeSpanConverter.cs" />
<Compile Include="Converters\TimeSpanStrConverter.cs" />
<Compile Include="Converters\TimeSpanToDoulbeConverter.cs" />
<Compile Include="Effects\MyRevealBorderBrush.cs" />
<Compile Include="Effects\MyRevealBorderLight.cs" />
<Compile Include="Effects\RevealBrush.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@

namespace AilianBT.Converters
{
public class TimeSpanConverter:IValueConverter
public class TimeSpanStrConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return ((TimeSpan)value).ToString(@"mm\:ss");
TimeSpan duration;
if (value is double seconds)
{
duration = TimeSpan.FromSeconds(seconds);
}
else
{
duration = (TimeSpan)value;
}
return duration.ToString(@"mm\:ss");
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
Expand Down
31 changes: 31 additions & 0 deletions AilianBT/Converters/TimeSpanToDoulbeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using Windows.UI.Xaml.Data;

namespace AilianBT.Converters
{
public class TimeSpanToSecondConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return ((TimeSpan)value).TotalSeconds;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}

public class SecondToTimeSpanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return TimeSpan.FromSeconds((double)value);
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
13 changes: 8 additions & 5 deletions AilianBT/Views/Controls/PlayerView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@

<converters:PlayStatusConverter x:Key="PlayingToVisible" StatusToVisible="Playing" />
<converters:PlayStatusConverter x:Key="PausedToVisible" StatusToVisible="Paused" />
<converters:TimeSpanConverter x:Key="DurationConverter" />
<converters:TimeSpanStrConverter x:Key="TimeSpanStrConverter" />
<converters:TimeSpanToSecondConverter x:Key="TimeSpanToSecondConverter" />
<converters:SecondToTimeSpanConverter x:Key="SecondToTimeSpanConverter" />
</UserControl.Resources>

<Grid>
Expand Down Expand Up @@ -330,7 +332,7 @@
FocusVisualPrimaryBrush="#FFE2E2E2"
FontSize="12"
Foreground="#FFE4E4E4"
Text="{x:Bind _playerVM.CurrentMusic.Position, Mode=OneWay, Converter={StaticResource DurationConverter}}" />
Text="{x:Bind sliderProgress.Value, Mode=OneWay, Converter={StaticResource TimeSpanStrConverter}}" />
<TextBlock Margin="2,0"
VerticalAlignment="Center"
FontSize="12"
Expand All @@ -339,16 +341,17 @@
<TextBlock VerticalAlignment="Center"
FontSize="12"
Foreground="#FFC4C4C4"
Text="{x:Bind _playerVM.CurrentMusic.Length, Mode=OneWay, Converter={StaticResource DurationConverter}}" />
Text="{x:Bind _playerVM.CurrentMusic.Length, Mode=OneWay, Converter={StaticResource TimeSpanStrConverter}}" />
</StackPanel>
</Grid>
<Slider x:Name="sliderProgress"
Grid.Row="1"
VerticalAlignment="Top"
Maximum="100"
Maximum="{x:Bind _playerVM.CurrentMusic.Length, Mode=OneWay, Converter={StaticResource TimeSpanToSecondConverter}}"
Minimum="0"
Style="{StaticResource ProgressSliderStyle}"
Value="{x:Bind _playerVM.PlaybackProgress, Mode=OneWay}" />
ThumbToolTipValueConverter="{StaticResource TimeSpanStrConverter}"
Value="{x:Bind _playerVM.CurrentMusic.Position, Mode=OneWay, Converter={StaticResource TimeSpanToSecondConverter}}" />
</Grid>
</Grid>
</Grid>
Expand Down
6 changes: 5 additions & 1 deletion AilianBT/Views/Controls/PlayerView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ private void _sliderProgressPointerPressed(object sender, PointerRoutedEventArgs

private void _sliderProgressPointerReleased(object sender, PointerRoutedEventArgs e)
{
_playerVM.Seek(sliderProgress.Value / (sliderProgress.Maximum - sliderProgress.Minimum));
var length = (sliderProgress.Maximum - sliderProgress.Minimum);
if (length > 0)
{
_playerVM.Seek(sliderProgress.Value / length);
}
_playerVM.Seeking = false;
}
#endregion
Expand Down

0 comments on commit f3d6db3

Please sign in to comment.