Skip to content

Commit

Permalink
Fixes digimezzo#552: Since adding FFmpegDecoder a NullReferenceExcept…
Browse files Browse the repository at this point in the history
…ion occurs very sporadically when starting playback
  • Loading branch information
raphgodart committed Nov 17, 2017
1 parent 4ecce9d commit f000c33
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions Dopamine.Common/Services/Playback/PlaybackService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,51 +228,68 @@ public TimeSpan GetCurrentTime
{
get
{
// Check if there is a Track playing
if (this.player != null && this.player.CanStop)
try
{
// This prevents displaying a current time which is larger than the total time
if (this.player.GetCurrentTime() <= this.player.GetTotalTime())
// Check if there is a Track playing
if (this.player != null && this.player.CanStop)
{
return this.player.GetCurrentTime();
// This prevents displaying a current time which is larger than the total time
if (this.player.GetCurrentTime() <= this.player.GetTotalTime())
{
return this.player.GetCurrentTime();
}
else
{
return this.player.GetTotalTime();
}
}
else
{
return this.player.GetTotalTime();
return new TimeSpan(0);
}
}
else
catch (Exception ex)
{
LogClient.Error("Failed to get current time. Returning 00:00. Exception: {0}", ex.Message);
return new TimeSpan(0);
}

}
}

public TimeSpan GetTotalTime
{
get
{
// Check if there is a Track playing

if (this.player != null && this.player.CanStop && this.HasCurrentTrack && this.CurrentTrack.Value.Duration != null)
try
{
// In some cases, the duration reported by TagLib is 1 second longer than the duration reported by CSCore.
if (this.CurrentTrack.Value.Duration > this.player.GetTotalTime().TotalMilliseconds)
// Check if there is a Track playing
if (this.player != null && this.player.CanStop && this.HasCurrentTrack && this.CurrentTrack.Value.Duration != null)
{
// To show the same duration everywhere, we report the TagLib duration here instead of the CSCore duration.
return new TimeSpan(0, 0, 0, 0, Convert.ToInt32(this.CurrentTrack.Value.Duration));
// In some cases, the duration reported by TagLib is 1 second longer than the duration reported by CSCore.
if (this.CurrentTrack.Value.Duration > this.player.GetTotalTime().TotalMilliseconds)
{
// To show the same duration everywhere, we report the TagLib duration here instead of the CSCore duration.
return new TimeSpan(0, 0, 0, 0, Convert.ToInt32(this.CurrentTrack.Value.Duration));
}
else
{
// Unless the TagLib duration is incorrect. In rare cases it is 0, even if
// CSCore reports a correct duration. In such cases, report the CSCore duration.
return this.player.GetTotalTime();
}
}
else
{
// Unless the TagLib duration is incorrect. In rare cases it is 0, even if
// CSCore reports a correct duration. In such cases, report the CSCore duration.
return this.player.GetTotalTime();
return new TimeSpan(0);
}
}
else
catch (Exception ex)
{
LogClient.Error("Failed to get total time. Returning 00:00. Exception: {0}", ex.Message);
return new TimeSpan(0);
}

}
}

Expand Down

0 comments on commit f000c33

Please sign in to comment.