private async void Page_Loaded(object sender, RoutedEventArgs e) { var downloadPath = await SettingUtil.GetDowloadPathAsync(); if (Directory.Exists(downloadPath)) { _musicListViewModel = Directory.GetFiles(downloadPath) .Where(m => GlobalConstants.Music_File_Suffix.Contains(System.IO.Path.GetExtension(m))) .Select(m => new MusicViewModel() { MusicName = System.IO.Path.GetFileNameWithoutExtension(m), FileUrl = m }) .ToList(); } MusicList.ItemsSource = _musicListViewModel; LocalCount.Text = (_musicListViewModel?.Count ?? 0).ToString(); }
/// <summary> /// 音乐下载 /// </summary> /// <param name="addressUrl"></param> /// <param name="localName"></param> public static async Task DownLoadMusicsAsync(Uri fileUri, string musicName, string singerName) { try { //Thread.Sleep(10000); var addressUri = fileUri; if (!addressUri.IsAbsoluteUri) { addressUri = new Uri(Path.GetFullPath(fileUri.OriginalString), UriKind.Absolute); } WebClient webClient = new WebClient(); var downloadPath = await SettingUtil.GetDowloadPathAsync(); Directory.CreateDirectory(downloadPath); webClient.DownloadFileAsync(addressUri, Path.Combine(downloadPath, $"{singerName}-{ musicName}")); webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted; } catch { throw new Exception($"{musicName}下载失败"); } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { TxtDownloadPath.Text = await SettingUtil.GetDowloadPathAsync(); }