mirror of
https://github.com/jayfunc/BetterLyrics.git
synced 2026-01-12 10:54:55 +08:00
fix: scrobble timer is still running when music is paused
This commit is contained in:
@@ -76,6 +76,7 @@
|
||||
<converter:LyricsLayoutOrientationNegationToOrientationConverter x:Key="LyricsLayoutOrientationNegationToOrientationConverter" />
|
||||
<converter:FileSourceTypeToIconConverter x:Key="FileSourceTypeToIconConverter" />
|
||||
<converter:PathToImageConverter x:Key="PathToImageConverter" />
|
||||
<converter:DoubleToDecimalConverter x:Key="DoubleToDecimalConverter" />
|
||||
|
||||
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
<TextBlock
|
||||
Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
|
||||
Style="{ThemeResource SubtitleTextBlockStyle}"
|
||||
Text="{x:Bind ViewModel.TotalDuration.TotalHours, Mode=OneWay}" />
|
||||
Text="{x:Bind ViewModel.TotalDuration.TotalHours, Mode=OneWay, Converter={StaticResource DoubleToDecimalConverter}}" />
|
||||
<TextBlock
|
||||
Margin="0,0,0,2"
|
||||
VerticalAlignment="Bottom"
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BetterLyrics.WinUI3.Converter
|
||||
{
|
||||
public partial class DoubleToDecimalConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value == null) return string.Empty;
|
||||
|
||||
if (double.TryParse(value.ToString(), out double number))
|
||||
{
|
||||
int decimalPlaces = 2;
|
||||
if (parameter != null && int.TryParse(parameter.ToString(), out int parsedParams))
|
||||
{
|
||||
decimalPlaces = parsedParams;
|
||||
}
|
||||
|
||||
return number.ToString($"F{decimalPlaces}");
|
||||
}
|
||||
|
||||
return value.ToString() ?? "";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,7 +239,6 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
|
||||
|
||||
var desiredSession = GetCurrentSession();
|
||||
|
||||
//RecordMediaSourceProviderInfo(mediaSession);
|
||||
if (mediaSession != desiredSession) return;
|
||||
|
||||
if (!IsMediaSourceEnabled(mediaSession.Id))
|
||||
@@ -254,6 +253,15 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
if (CurrentIsPlaying)
|
||||
{
|
||||
_scrobbleStopwatch.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
_scrobbleStopwatch.Stop();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -349,7 +357,7 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
|
||||
}
|
||||
}
|
||||
}
|
||||
_scrobbleStopwatch.Restart();
|
||||
_scrobbleStopwatch.Reset();
|
||||
|
||||
CurrentSongInfo = new SongInfo
|
||||
{
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace BetterLyrics.WinUI3.Services.PlayHistoryService
|
||||
|
||||
var totalMs = await context.PlayHistory
|
||||
.Where(x => x.StartedAt >= start && x.StartedAt <= end)
|
||||
.SumAsync(x => x.DurationPlayedMs); // 直接在数据库层面求和
|
||||
.SumAsync(x => Math.Min(x.DurationPlayedMs, x.TotalDurationMs)); // 防止超过歌曲本身时长
|
||||
|
||||
return TimeSpan.FromMilliseconds(totalMs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user