Adding initial playback bar logic.
This commit is contained in:
37
Harmonia.UI/Converters/SecondsToStringConverter.cs
Normal file
37
Harmonia.UI/Converters/SecondsToStringConverter.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Avalonia.Data.Converters;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Harmonia.UI.Converters;
|
||||
|
||||
public sealed class SecondsToStringConverter : IValueConverter
|
||||
{
|
||||
public SecondsToStringConverter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not double doubleValue)
|
||||
return null;
|
||||
|
||||
TimeSpan timeSpan = TimeSpan.FromSeconds(doubleValue);
|
||||
|
||||
if (timeSpan.Hours >= 1)
|
||||
return timeSpan.ToString(@"%h\:mm\:ss");
|
||||
|
||||
return timeSpan.ToString(@"%m\:ss");
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
if (value is not string stringValue)
|
||||
return null;
|
||||
|
||||
return TimeSpan.Parse(stringValue);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user