mirror of
https://github.com/jayfunc/BetterLyrics.git
synced 2026-01-13 03:34:55 +08:00
93 lines
2.7 KiB
C#
93 lines
2.7 KiB
C#
// 2025/6/23 by Zhe Fang
|
|
|
|
using BetterLyrics.WinUI3.Hooks;
|
|
using BetterLyrics.WinUI3.Models;
|
|
using BetterLyrics.WinUI3.Services.LiveStatesService;
|
|
using BetterLyrics.WinUI3.Services.MediaSessionsService;
|
|
using BetterLyrics.WinUI3.Views;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BetterLyrics.WinUI3.ViewModels
|
|
{
|
|
public partial class NowPlayingPageViewModel : BaseViewModel
|
|
{
|
|
public IMediaSessionsService MediaSessionsService { get; private set; }
|
|
private readonly ILiveStatesService _liveStatesService;
|
|
|
|
[ObservableProperty]
|
|
public partial LiveStates LiveStates { get; set; }
|
|
|
|
[ObservableProperty]
|
|
public partial int Volume { get; set; }
|
|
|
|
[ObservableProperty]
|
|
public partial double BottomCommandGridOpacity { get; set; }
|
|
|
|
[ObservableProperty]
|
|
public partial double BottomCommandFlyoutTriggerOpacity { get; set; }
|
|
|
|
[ObservableProperty]
|
|
public partial float TimelineSliderThumbOpacity { get; set; } = 0f;
|
|
|
|
[ObservableProperty]
|
|
public partial LyricsLine? TimelineSliderThumbLyricsLine { get; set; }
|
|
|
|
[ObservableProperty]
|
|
public partial double TimelineSliderThumbSeconds { get; set; } = 0;
|
|
|
|
public NowPlayingPageViewModel(IMediaSessionsService mediaSessionsService, ILiveStatesService liveStatesService)
|
|
{
|
|
_liveStatesService = liveStatesService;
|
|
MediaSessionsService = mediaSessionsService;
|
|
|
|
LiveStates = _liveStatesService.LiveStates;
|
|
|
|
Volume = SystemVolumeHook.MasterVolume;
|
|
SystemVolumeHook.VolumeNotification += SystemVolumeHelper_VolumeNotification;
|
|
}
|
|
|
|
private void SystemVolumeHelper_VolumeNotification(object? sender, int e)
|
|
{
|
|
Volume = e;
|
|
}
|
|
|
|
partial void OnTimelineSliderThumbSecondsChanged(double value)
|
|
{
|
|
TimelineSliderThumbLyricsLine = MediaSessionsService.CurrentLyricsData?.GetLyricsLine(value);
|
|
}
|
|
|
|
[RelayCommand]
|
|
private static void OpenSettingsWindow()
|
|
{
|
|
WindowHook.OpenOrShowWindow<SettingsWindow>();
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task PlaySongAsync()
|
|
{
|
|
await MediaSessionsService.PlayAsync();
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task PauseSongAsync()
|
|
{
|
|
await MediaSessionsService.PauseAsync();
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task PreviousSongAsync()
|
|
{
|
|
await MediaSessionsService.PreviousAsync();
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task NextSongAsync()
|
|
{
|
|
await MediaSessionsService.NextAsync();
|
|
}
|
|
|
|
}
|
|
}
|