修复灵动词岛崩溃

This commit is contained in:
LanZhan
2026-03-04 23:49:23 +08:00
parent 878cc57dbf
commit 7972126f12
2 changed files with 37 additions and 22 deletions

View File

@@ -45,10 +45,14 @@ public sealed partial class LyricManager(SharedPlaybackState state)
/// </summary>
public async void GetSongLyric()
{
CurrentLyricSlices = await LyricParser.GetLyricSlices(
var slices = await LyricParser.GetLyricSlices(
_state.CurrentSong!.Lyric,
_state.CurrentSong!.Duration
);
_dispatcher.TryEnqueue(() =>
{
CurrentLyricSlices = slices;
CurrentLyricIndex = 0;
if (CurrentLyricSlices.Count > 0)
@@ -60,6 +64,7 @@ public sealed partial class LyricManager(SharedPlaybackState state)
{
CurrentLyricContent = "";
}
});
}
/// <summary>
@@ -95,26 +100,36 @@ public sealed partial class LyricManager(SharedPlaybackState state)
return;
}
var oldSlice = CurrentLyricSlices[CurrentLyricIndex];
var newSlice = CurrentLyricSlices[newIndex];
var newContent = newSlice.Content;
_dispatcher.TryEnqueue(() =>
{
oldSlice.IsCurrent = false;
if (newIndex < 0 || newIndex >= CurrentLyricSlices.Count)
{
return;
}
if (CurrentLyricIndex >= 0 && CurrentLyricIndex < CurrentLyricSlices.Count)
{
CurrentLyricSlices[CurrentLyricIndex].IsCurrent = false;
}
var newSlice = CurrentLyricSlices[newIndex];
newSlice.IsCurrent = true;
CurrentLyricContent = newContent;
});
CurrentLyricContent = newSlice.Content;
CurrentLyricIndex = newIndex;
});
}
/// <summary>
/// 重置歌词状态
/// </summary>
public void Reset()
{
_dispatcher.TryEnqueue(() =>
{
CurrentLyricIndex = 0;
CurrentLyricContent = "";
CurrentLyricSlices.Clear();
});
}
public void Dispose()

View File

@@ -57,13 +57,13 @@
<PackageReference Include="ManagedBass.Fx" Version="4.0.2" />
<PackageReference Include="ManagedBass.Wasapi" Version="4.0.2" />
<PackageReference Include="MemoryPack" Version="1.21.4" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.3" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.3.2" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.8.260101001" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.8.260209005" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="3.0.1" />
<PackageReference Include="TagLibSharp" Version="2.3.0" />
<PackageReference Include="WinUIEx" Version="2.9.0" />
<PackageReference Include="ZLinq" Version="1.5.4" />
<PackageReference Include="ZLinq" Version="1.5.5" />
<PackageReference Include="ZLogger" Version="2.5.10" />
</ItemGroup>
<ItemGroup>