Skip to content

Commit d48582c

Browse files
author
theweavrs
committed
fixed null reference when playling next song in group
1 parent 2cecf69 commit d48582c

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

BreadPlayer.Views.UWP/Assets/whatsnew.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
1. Bug fixes
33
2. Notifications are now queued.
44
3. Notifications now include a "Close" button.
5-
4. Improved performance.
5+
4. Improved performance.
6+
5. Fixed playlist import.
7+
6. Added donate dialog
8+
7. Made Bread Player Free in the store again.
9+
8. Please show your support by Donating! Love you all!

BreadPlayer.Views.UWP/ViewModels/ShellViewModel.cs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ public async Task<Mediafile> GetUpcomingSong(bool isNext = false)
514514
}
515515
else if (IsSourceGrouped)
516516
{
517-
toPlayFile = GetNextOrPrevSongInGroup(false);
517+
toPlayFile = GetNextOrPrevSongInGroup(false) ?? throw new NullReferenceException("Cannot get next song in group.");
518518
}
519519
else
520520
{
@@ -569,27 +569,34 @@ private void UpdateCurrentlyPlayingSongIndex()
569569
}
570570
private Mediafile GetNextOrPrevSongInGroup(bool prev = false)
571571
{
572-
//get current group (the group in which current song is playing).
573-
Grouping<IGroupKey, Mediafile> currentGroup = TracksCollection.GetCurrentlyPlayingGroup();
574-
575-
//get the index of the song playing in the currentGroup (with reference to the currentGroup)
576-
int currentSongIndex = currentGroup.GetPlayingSongIndexInGroup();
577-
578-
//get next song index (depending on the parameters).
579-
int nextSongIndex = prev ? currentSongIndex - 1 : currentSongIndex + 1;
580-
581-
//get condition for next/prev group.
582-
bool nextGroupCondition = nextSongIndex.Equals(prev ? -1 : currentGroup.Count);
583-
584-
//get next/prev group index
585-
int nextGroupIndex = prev ? TracksCollection.IndexOf(currentGroup) - 1 : TracksCollection.IndexOf(currentGroup) + 1;
586-
587-
//get next/prev group.
588-
Grouping<IGroupKey, Mediafile> nextGroup = nextGroupCondition ? TracksCollection.ElementAt(nextGroupIndex) : currentGroup;
589-
590-
//get nextSong index depending on if the group is new or old.
591-
int toPlaySongIndex = nextGroup.Equals(currentGroup) ? nextSongIndex : 0;
592-
return nextGroup.ElementAt(toPlaySongIndex);
572+
try
573+
{
574+
//get current group (the group in which current song is playing).
575+
Grouping<IGroupKey, Mediafile> currentGroup = TracksCollection.GetCurrentlyPlayingGroup();
576+
577+
//get the index of the song playing in the currentGroup (with reference to the currentGroup)
578+
int currentSongIndex = currentGroup.GetPlayingSongIndexInGroup();
579+
580+
//get next song index (depending on the parameters).
581+
int nextSongIndex = prev ? currentSongIndex - 1 : currentSongIndex + 1;
582+
583+
//get condition for next/prev group.
584+
bool nextGroupCondition = nextSongIndex.Equals(prev ? -1 : currentGroup.Count);
585+
586+
//get next/prev group index
587+
int nextGroupIndex = prev ? TracksCollection.IndexOf(currentGroup) - 1 : TracksCollection.IndexOf(currentGroup) + 1;
588+
589+
//get next/prev group.
590+
Grouping<IGroupKey, Mediafile> nextGroup = nextGroupCondition ? TracksCollection.ElementAt(nextGroupIndex) : currentGroup;
591+
592+
//get nextSong index depending on if the group is new or old.
593+
int toPlaySongIndex = nextGroup.Equals(currentGroup) ? nextSongIndex : 0;
594+
return nextGroup.ElementAt(toPlaySongIndex);
595+
}
596+
catch (NullReferenceException)
597+
{
598+
return null;
599+
}
593600
}
594601

595602
private async void PlayNext()

0 commit comments

Comments
 (0)