private void ParsingThread() { Thread.Sleep(1000); try { JsonArrayCollection items = JSONHelper.getJSONArray(url_yotube); Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { foreach (JsonObjectCollection item in items) { string title = item["title"].GetValue().ToString(); ////수정해야 // string mUrl = item["singer"].GetValue().ToString(); // string playTime = item["singer"].GetValue().ToString(); string mUrl = item["url"].GetValue().ToString().Replace("http://www.youtube.com/watch?v=", "");; string playTime = item["time"].GetValue().ToString(); MusicItem mitem = new MusicItem(); mitem.title = title; mitem.url = mUrl; mitem.time = playTime; musicCollection.Add(mitem); } })); Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { HideDrawerMenu(); })); } catch (Exception e) { Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { MessageBoxOrange.ShowDialog("Exception", e.Message); HideDrawerMenu(); })); } }
private void ParsingThread_For_addfavorite() { Thread.Sleep(1000); try { JsonArrayCollection items = JSONHelper.getJSONArray(url); MusicCollection tmp_musicCollection = new MusicCollection(); Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { foreach (JsonObjectCollection item in items) { string title = item["title"].GetValue().ToString(); ////수정해야 // string mUrl = item["singer"].GetValue().ToString(); // string playTime = item["singer"].GetValue().ToString(); string mUrl = item["url"].GetValue().ToString().Replace("http://www.youtube.com/watch?v=", "");; string playTime = item["time"].GetValue().ToString(); MusicItem mitem = new MusicItem(); mitem.title = title; mitem.url = mUrl; mitem.time = playTime; tmp_musicCollection.Add(mitem); } PlaylistItem pitem = (PlaylistItem)result_playlist.SelectedItem; String path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string filedirectory = path + @"\OrangePlayer\favoritePlaylist"; // string filedirectory = System.AppDomain.CurrentDomain.BaseDirectory + "/favoritePlaylist"; if (!Directory.Exists(filedirectory)) { Directory.CreateDirectory(filedirectory); } string filepath = string.Format("{0}/{1}.orm", filedirectory, pitem.name); //System.AppDomain.CurrentDomain.BaseDirectory //System.IO.Directory.GetCurrentDirectory(); File.WriteAllText(filepath, Security.Encrypt(Newtonsoft.Json.JsonConvert.SerializeObject(tmp_musicCollection))); if (File.Exists(filepath)) { PlaylistItem item = new PlaylistItem(); item.name = pitem.name; item.filePath = filepath; myFavoriteMgr.MyfavoriteCollection.Add(item); } else { MessageBoxOrange.ShowDialog("Exception", "failed to create the file"); } })); } catch (Exception e) { Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { MessageBoxOrange.ShowDialog("Exception", e.Message); })); } Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { ProgressRing.IsActive = false; progressGrid.Visibility = Visibility.Collapsed; })); }