Skip to content

Commit

Permalink
Fixed NRE in Sample.UI when selection is null.
Browse files Browse the repository at this point in the history
  • Loading branch information
DubyaDude committed Jan 20, 2024
1 parent c45e9a4 commit fdeebaf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Sample.UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
<Image x:Name="SongImage" Height="160" Canvas.Left="10" Canvas.Top="11" Width="160"/>
<Label x:Name="SongTitle" Content="TITLE" Canvas.Left="179" Canvas.Top="2" Height="64" Width="449" FontSize="50" FontFamily="Segoe UI BOLD"/>
<Label x:Name="SongAuthor" Content="Author" Canvas.Left="179" Canvas.Top="59" Height="35" Width="449" FontSize="25" FontFamily="Segoe UI"/>
<Button x:Name="ControlBack" Content="◀◀" Canvas.Left="179" Canvas.Top="105" Height="65" Width="65" Click="Back_Click" FontSize ="27" FontFamily="Segoe UI BOLD"/>
<Button x:Name="ControlPlayPause" Content="▶️" Canvas.Left="249" Canvas.Top="105" Height="65" Width="65" Click="PlayPause_Click" FontSize ="27" FontFamily="Segoe UI BOLD"/>
<Button x:Name="ControlForward" Content="▶️▶️" Canvas.Left="319" Canvas.Top="105" Height="65" Width="65" Click="Forward_Click" FontSize ="27" FontFamily="Segoe UI BOLD"/>
<Button x:Name="ControlBack" IsEnabled="False" Content="◀◀" Canvas.Left="179" Canvas.Top="105" Height="65" Width="65" Click="Back_Click" FontSize ="27" FontFamily="Segoe UI BOLD"/>
<Button x:Name="ControlPlayPause" IsEnabled="False" Content="▶️" Canvas.Left="249" Canvas.Top="105" Height="65" Width="65" Click="PlayPause_Click" FontSize ="27" FontFamily="Segoe UI BOLD"/>
<Button x:Name="ControlForward" IsEnabled="False" Content="▶️▶️" Canvas.Left="319" Canvas.Top="105" Height="65" Width="65" Click="Forward_Click" FontSize ="27" FontFamily="Segoe UI BOLD"/>
</Canvas>
</ui:NavigationView>

Expand Down
29 changes: 22 additions & 7 deletions Sample.UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,19 @@ private void SongList_SelectionChanged(NavigationView navView, NavigationViewSel
currentSession.OnMediaPropertyChanged += CurrentSession_OnMediaPropertyChanged;
currentSession.OnPlaybackStateChanged += CurrentSession_OnPlaybackStateChanged;
CurrentSession_OnPlaybackStateChanged(currentSession);
ControlPlayPause.IsEnabled = true;
ControlBack.IsEnabled = true;
ControlForward.IsEnabled = true;
}
else
{
SongImage.Source = null;
SongTitle.Content = "TITLE";
SongAuthor.Content = "Author";
ControlPlayPause.Content = "▶️";
ControlPlayPause.IsEnabled = false;
ControlBack.IsEnabled = false;
ControlForward.IsEnabled = false;
}
}

Expand Down Expand Up @@ -136,22 +142,31 @@ private void UpdateUI(MediaSession mediaSession)

private async void Back_Click(object sender, RoutedEventArgs e)
{
await currentSession?.ControlSession.TrySkipPreviousAsync();
if(currentSession != null)
{
await currentSession.ControlSession.TrySkipPreviousAsync();
}
}

private async void PlayPause_Click(object sender, RoutedEventArgs e)
{
var controlsInfo = currentSession?.ControlSession.GetPlaybackInfo().Controls;
if (currentSession != null)
{
var controlsInfo = currentSession.ControlSession.GetPlaybackInfo().Controls;

if (controlsInfo?.IsPauseEnabled == true)
await currentSession?.ControlSession.TryPauseAsync();
else if (controlsInfo?.IsPlayEnabled == true)
await currentSession?.ControlSession.TryPlayAsync();
if (controlsInfo.IsPauseEnabled == true)
await currentSession.ControlSession.TryPauseAsync();
else if (controlsInfo.IsPlayEnabled == true)
await currentSession.ControlSession.TryPlayAsync();
}
}

private async void Forward_Click(object sender, RoutedEventArgs e)
{
await currentSession?.ControlSession.TrySkipNextAsync();
if (currentSession != null)
{
await currentSession.ControlSession.TrySkipNextAsync();
}
}
}

Expand Down

0 comments on commit fdeebaf

Please sign in to comment.