Skip to content

Commit

Permalink
Make sure that music file exists before start of playback
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Sep 5, 2017
1 parent b0a38d8 commit 6751b22
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion App/Presenters/Controls/MusicControlPresenter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Threading;
using System.Timers;
using CollectionManager.DataTypes;
Expand Down Expand Up @@ -102,7 +103,7 @@ private void ModelOnBeatmapChanged(object sender, EventArgs eventArgs)
if (map == null || !_view.IsAutoPlayEnabled)
return;
var audioLocation = ((BeatmapExtension)map).FullAudioFileLocation();
if ((_lastAudioFileLocation == audioLocation || string.IsNullOrWhiteSpace(audioLocation)) && _view.IsMusicPlayerMode && !musicPlayer.IsPlaying)
if (ShouldSkipTrack(audioLocation))
{
//Run as worker to avoid eventual stack overflow exception (eg. too many maps with no audio file in a row)
RunAsWorker(() => _model.EmitNextMapRequest());
Expand All @@ -112,6 +113,14 @@ private void ModelOnBeatmapChanged(object sender, EventArgs eventArgs)
PlayBeatmap(map);
}

private bool ShouldSkipTrack(string audioLocation)
{
if ((_lastAudioFileLocation == audioLocation || string.IsNullOrWhiteSpace(audioLocation)) &&
_view.IsMusicPlayerMode && !musicPlayer.IsPlaying)
return true;

return !File.Exists(audioLocation);
}
private void PlayBeatmap(Beatmap map)
{
var audioLocation = ((BeatmapExtension)map).FullAudioFileLocation();
Expand Down

0 comments on commit 6751b22

Please sign in to comment.