/// <summary>
/// Prepares for playing the next video.
/// </summary>
/// <param name="queuePos">The video position to select. 0 for current, 1 for next.</param>
/// <param name="attempts">The number of attemps already made, to avoid infinite loop.</param>
/// <returns>Whether the file is downloading.</returns>
private async Task <bool> PrepareNextVideoAsync(int queuePos, int attempts)
{
bool FileExists = false;
if (nextVideo != null)
{
FileExists = File.Exists(Settings.NaturalGroundingFolder + nextVideo.FileName);
}
if (!FileExists)
{
// If file doesn't exist and can't be downloaded, select another one.
if (!Settings.SavedFile.AutoDownload || nextVideo == null || nextVideo.DownloadUrl.Length == 0)
{
await SelectNextVideoAsync(queuePos, false, attempts + 1).ConfigureAwait(false);
}
// If file doesn't exist and can be downloaded, download it.
else if (nextVideo != null && nextVideo.DownloadUrl.Length > 0)
{
Application.Current.Dispatcher.Invoke(() => PlaylistChanged?.Invoke(this, new EventArgs()));
await downloadManager.DownloadVideoAsync(nextVideo, queuePos, Download_Complete).ConfigureAwait(false);
return(true);
}
}
return(false);
}