From 976b67d1fb2cec0e735af65f82ba8dc08df7a341 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 7 Jun 2021 09:03:53 -0700 Subject: [PATCH] Safer handling of current value setting --- RedBookPlayer/Player.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/RedBookPlayer/Player.cs b/RedBookPlayer/Player.cs index ff67ac6..db0c40c 100644 --- a/RedBookPlayer/Player.cs +++ b/RedBookPlayer/Player.cs @@ -39,6 +39,13 @@ namespace RedBookPlayer if(Image == null) return; + // If the value is the same, don't do anything + if(value == _currentTrack) + return; + + // Check if we're incrementing or decrementing the track + bool increment = value > _currentTrack; + // Ensure that the value is valid, wrapping around if necessary if(value >= Image.Tracks.Count) _currentTrack = 0; @@ -76,7 +83,12 @@ namespace RedBookPlayer // If we're not playing data tracks, skip if(!App.Settings.PlayDataTracks && TrackType == TrackTypeValue.Data) - NextTrack(); + { + if(increment) + NextTrack(); + else + PreviousTrack(); + } } } @@ -92,6 +104,10 @@ namespace RedBookPlayer if(Image == null) return; + // If the value is the same, don't do anything + if(value == _currentIndex) + return; + // Cache the current track for easy access Track track = Image.Tracks[CurrentTrack]; @@ -121,6 +137,10 @@ namespace RedBookPlayer if(Image == null) return; + // If the value is the same, don't do anything + if(value == _currentSector) + return; + // Cache the current track for easy access Track track = Image.Tracks[CurrentTrack];