/// <summary> /// Gets songs from the currently loaded songs according to the provided paramters. /// </summary> /// <param name="index">The index to start at.</param> /// <param name="query">The query string.</param> /// <param name="amount">The maximum amount of songs to return.</param> /// <returns>The songs.</returns> public List <SongInformation> GetSongs(int index = 0, string query = null, int amount = 50) { query = query.ToLower(); var matches = _sourceList?.Where(s => (s.Title != null && s.Title.ToLower().Contains(query)) || (s.Band != null && s.Band.ToLower().Contains(query)) || (s.Location != null && s.Location.ToLower().Contains(query))) .OrderBy(s => string.IsNullOrEmpty(query) || !_shuffle ? s.FileName : s.Title).Skip(index).Take(amount).ToList(); if (matches != null) { var resolveTasks = new List <Task>(); for (var i = 0; i < matches.Count; i++) { var j = i; var task = Task.Run(() => { matches[j] = SongInfoController.Resolve(matches[j]); var sourceIndex = _sourceList.FindIndex(s => s.Location == matches[j].Location); _sourceList[sourceIndex] = matches[j]; }); resolveTasks.Add(task); } Task.WaitAll(resolveTasks.ToArray()); } return(matches); }
/// <summary> /// Play from key (path). /// </summary> /// <param name="key"></param> private void PlayFromFileLocation(string key) { SongInformation song = _sourceList.FirstOrDefault(ct => ct.Location == key); if (song != null) { if (!song.IsResolved && !song.IsInternetLocation) { SongInfoController.Resolve(song); } Load(song); } }