diff --git a/GenshinLyreMidiPlayer.WPF/GenshinLyreMidiPlayer.WPF.csproj b/GenshinLyreMidiPlayer.WPF/GenshinLyreMidiPlayer.WPF.csproj index b2f2b93..d617d24 100644 --- a/GenshinLyreMidiPlayer.WPF/GenshinLyreMidiPlayer.WPF.csproj +++ b/GenshinLyreMidiPlayer.WPF/GenshinLyreMidiPlayer.WPF.csproj @@ -6,7 +6,7 @@ true GenshinLyreMidiPlayer.WPF.App app.manifest - 1.9.2 + 1.9.3 item_windsong_lyre.ico enable https://github.com/sabihoshi/GenshinLyreMidiPlayer diff --git a/GenshinLyreMidiPlayer.WPF/ViewModels/LyrePlayerViewModel.cs b/GenshinLyreMidiPlayer.WPF/ViewModels/LyrePlayerViewModel.cs index 09fd4de..d1b9a42 100644 --- a/GenshinLyreMidiPlayer.WPF/ViewModels/LyrePlayerViewModel.cs +++ b/GenshinLyreMidiPlayer.WPF/ViewModels/LyrePlayerViewModel.cs @@ -25,7 +25,7 @@ public class LyrePlayerViewModel : Screen, { private static readonly Settings Settings = Settings.Default; private readonly IEventAggregator _events; - private readonly MediaPlayer _player; + private readonly MediaPlayer? _player; private readonly SettingsPageViewModel _settings; private readonly OutputDevice _speakers; private readonly PlaybackCurrentTimeWatcher _timeWatcher; @@ -50,13 +50,19 @@ public LyrePlayerViewModel(IContainer ioc, _timeWatcher.CurrentTimeChanged += OnSongTick; - _player = ioc.Get(); + // SystemMediaTransportControls is only supported on Windows 10 and later + // https://docs.microsoft.com/en-us/uwp/api/windows.media.systemmediatransportcontrols + if (Environment.OSVersion.Platform == PlatformID.Win32NT && + Environment.OSVersion.Version.Major >= 10) + { + _player = ioc.Get(); - _player.CommandManager.NextReceived += (_, _) => Next(); - _player.CommandManager.PreviousReceived += (_, _) => Previous(); + _player.CommandManager.NextReceived += (_, _) => Next(); + _player.CommandManager.PreviousReceived += (_, _) => Previous(); - _player.CommandManager.PlayReceived += (_, _) => PlayPause(); - _player.CommandManager.PauseReceived += (_, _) => PlayPause(); + _player.CommandManager.PlayReceived += (_, _) => PlayPause(); + _player.CommandManager.PauseReceived += (_, _) => PlayPause(); + } } public BindableCollection MidiInputs { get; } = new() @@ -127,7 +133,8 @@ public MidiInput? SelectedMidiInput } } - private MusicDisplayProperties Display => _player.SystemMediaTransportControls.DisplayUpdater.MusicProperties; + private MusicDisplayProperties? Display => + _player?.SystemMediaTransportControls.DisplayUpdater.MusicProperties; public Playback? Playback { get; private set; } @@ -139,7 +146,8 @@ public MidiInput? SelectedMidiInput public string PlayPauseIcon => Playback?.IsRunning ?? false ? PauseIcon : PlayIcon; - private SystemMediaTransportControls Controls => _player.SystemMediaTransportControls; + private SystemMediaTransportControls? Controls => + _player?.SystemMediaTransportControls; public TimeSpan CurrentTime => TimeSpan.FromSeconds(SongSlider); @@ -176,30 +184,31 @@ public void UpdateButtons() NotifyOfPropertyChange(() => PlayPauseIcon); NotifyOfPropertyChange(() => MaximumTime); - var controls = Controls; + if (Controls is not null && Display is not null) + { + Controls.IsPlayEnabled = CanHitPlayPause; + Controls.IsPauseEnabled = CanHitPlayPause; - controls.IsPlayEnabled = CanHitPlayPause; - controls.IsPauseEnabled = CanHitPlayPause; + Controls.IsNextEnabled = CanHitNext; + Controls.IsPreviousEnabled = CanHitPrevious; - controls.IsNextEnabled = CanHitNext; - controls.IsPreviousEnabled = CanHitPrevious; + Controls.PlaybackStatus = + Playlist.OpenedFile is null ? MediaPlaybackStatus.Closed : + Playback is null ? MediaPlaybackStatus.Stopped : + Playback.IsRunning ? MediaPlaybackStatus.Playing : + MediaPlaybackStatus.Paused; - controls.PlaybackStatus = - Playlist.OpenedFile is null ? MediaPlaybackStatus.Closed : - Playback is null ? MediaPlaybackStatus.Stopped : - Playback.IsRunning ? MediaPlaybackStatus.Playing : - MediaPlaybackStatus.Paused; + var file = Playlist.OpenedFile; + if (file is not null) + { + var position = $"{file.Position}/{Playlist.GetPlaylist().Count}"; - var file = Playlist.OpenedFile; - if (file is not null) - { - var position = $"{file.Position}/{Playlist.GetPlaylist().Count}"; + Display.Title = file.Title; + Display.Artist = $"Playing {position} {CurrentTime:mm\\:ss}"; + } - Display.Title = file.Title; - Display.Artist = $"Playing {position} {CurrentTime:mm\\:ss}"; + Controls.DisplayUpdater.Update(); } - - controls.DisplayUpdater.Update(); } private void InitializeTracks() diff --git a/GenshinLyreMidiPlayer.WPF/app.manifest b/GenshinLyreMidiPlayer.WPF/app.manifest index d72e750..78e2df3 100644 --- a/GenshinLyreMidiPlayer.WPF/app.manifest +++ b/GenshinLyreMidiPlayer.WPF/app.manifest @@ -28,19 +28,19 @@ and Windows will automatically select the most compatible environment. --> - + - + - + - + - +