public ViewModelTracklist(Entry plentry) { this.plentry = plentry; tracklistentry = new ObservableCollection<Entry>(); completed = false; GetApiResponse(); }
private void PopulateCollection(JObject response) { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { try { foreach (JObject entry in response["feed"]["entry"]) { Entry newent = new Entry(); try { newent.Id = (string)entry["yt$playlistId"]["$t"]; newent.Title = (string)entry["title"]["$t"]; newent.Source = (string)entry["content"]["src"]; newent.Title = StringExtension.TitleCase(newent.Title); newent.ImageSource = (string)entry["media$group"]["media$thumbnail"][0]["url"]; newent.Count = (int)entry["yt$countHint"]["$t"]; newent.Updated = (DateTime)entry["updated"]["$t"]; playlistentry.Add(newent); } catch (Exception e) { Resources.ErrorLogging.Log(this.GetType().ToString(), e.Message, "PlaylistViewmodel", string.Empty); if(newent.Id != null && newent.Title != null && newent.Source != null) playlistentry.Add(newent); } } } catch (Exception ex) { Resources.ErrorLogging.Log(this.GetType().ToString(),ex.Message, "PlaylistViewmodel",string.Empty);//ErrorLogging.Log(ex.Message + " response: " + e.API.Response); } }); Completed = true; }
private void PopulateCollection(JObject response) { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { try { string id = ""; foreach (JObject entry in response["feed"]["entry"]) { Entry newent = new Entry(); newent.PlaylistID = plentry.Id; newent.EntryID = (string)entry["id"]["$t"]; string[] splittat = {"playlist:"}; newent.EntryID = newent.EntryID.Split(splittat,StringSplitOptions.None)[1].Split(':')[1]; newent.Id = (string)entry["media$group"]["yt$videoid"]["$t"]; newent.Title = (string)entry["title"]["$t"]; newent.ImageSource = (string)entry["media$group"]["media$thumbnail"][0]["url"]; string dura = (string)entry["media$group"]["yt$duration"]["seconds"]; newent.Duration = TimeSpan.FromSeconds(double.Parse(dura)); foreach (JObject jo in entry["link"]) { string src; if ((string)jo["type"] == "text/html" && (string)jo["rel"] == "alternate") { src = (string)jo["href"]; string[] src_split = src.Split('&'); newent.Source = src_split[0]; break; } } if (newent.Source == null) throw new WebException("Cant get Video Address from API"); id = newent.Id; string filename = plentry.Id + "\\" + id + ".mp3"; string offline = "Not Synced"; SolidColorBrush col = new SolidColorBrush(Colors.Red); if (ISOHelper.FileExists(filename)) { offline = "Available offline"; col.Color = Colors.Green; } newent.AvailablityColor = col; newent.Offline = offline; tracklistentry.Add(newent); } } catch (Exception ex) { ErrorLogging.Log(this.GetType().ToString(), ex.Message, "ViewModelTracklist", "probablyJSONResponse"); } }); completed = true; }
void back_worker_DoWork(object sender, DoWorkEventArgs e) { ToggleProgressBar("Loading..."); plentry = ViewModelPlaylist.playlistentry.ElementAt((int)e.Argument); viewmodel = new ViewModelTracklist(plentry); while (!viewmodel.completed) { System.Threading.Thread.Sleep(3000); } }
private void PopulateCollection(JObject json) { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { try { foreach (JObject entry in json["feed"]["entry"]) { Entry newent = new Entry(); newent.Id = (string)entry["media$group"]["yt$videoid"]["$t"]; newent.Title = (string)entry["title"]["$t"]; newent.ImageSource = (string)entry["media$group"]["media$thumbnail"][0]["url"]; string dura = (string)entry["media$group"]["yt$duration"]["seconds"]; newent.Duration = TimeSpan.FromSeconds(double.Parse(dura)); newent.Credit = (string)entry["media$group"]["media$credit"][0]["yt$display"]; Results.Add(newent); } } catch (Exception e) { ErrorLogging.Log(this.GetType().ToString(), e.Message, "SearchResults", string.Empty); } }); }