Example #1
0
 private static async Task<NowPlay> GetNowPlay()
 {
     try
     {
         var datafolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Data");
         var nowplayfile = await datafolder.GetFileAsync("nowplay.json");
         var json = await Windows.Storage.FileIO.ReadTextAsync(nowplayfile);
         var obj = Windows.Data.Json.JsonObject.Parse(json);
         var nowplay = new NowPlay();
         nowplay.title = obj.GetNamedString("title");
         nowplay.singername = obj.GetNamedString("singername");
         return nowplay;
     }
     catch (Exception)
     {
         return null;
     }
 }
Example #2
0
 public static string ToJsonData(NowPlay nowplay)
 {
     var obj = new JsonObject();
     obj.Add("title", JsonValue.CreateStringValue(nowplay.title));
     obj.Add("url", JsonValue.CreateStringValue(nowplay.url));
     obj.Add("imgurl", JsonValue.CreateStringValue(nowplay.imgurl));
     obj.Add("albumid", JsonValue.CreateStringValue(nowplay.albumid));
     obj.Add("singername", JsonValue.CreateStringValue(nowplay.singername));
     try
     {
         var num = nowplay.pics.Count;
         var arry = new JsonArray();
         foreach (var pic in nowplay.pics)
         {
             arry.Add(JsonValue.CreateStringValue(pic));
         }
         obj.Add("pics", arry);
     }
     catch (Exception)
     {
         
     }
     var result = obj.ToString();
     return result;
 }
Example #3
0
 private void UpdatePrimaryTile(NowPlay nowplay)
 {
     try
     {
         var updater = TileUpdateManager.CreateTileUpdaterForApplication();
         updater.EnableNotificationQueueForWide310x150(true);
         updater.EnableNotificationQueueForSquare150x150(true);
         updater.EnableNotificationQueueForSquare310x310(true);
         updater.EnableNotificationQueue(true);
         updater.Clear();
         var doc = new Windows.Data.Xml.Dom.XmlDocument();
         string xml = "";
         /*
         if (nowplay.imgurl == null && nowplay.imgurl == "")
         {
             xml = string.Format(TileTemplateXml2, nowplay.title, nowplay.singername, "这是歌词");
         }
         else
         {
             xml = string.Format(TileTemplateXml1, nowplay.imgurl, nowplay.title, nowplay.singername, "这是歌词");
         }
         */
         xml = string.Format(TileTemplateXml,nowplay.imgurl, nowplay.title, nowplay.singername);
         doc.LoadXml(WebUtility.HtmlDecode(xml), new XmlLoadSettings
         {
             ProhibitDtd = false,
             ValidateOnParse = false,
             ElementContentWhiteSpace = false,
             ResolveExternals = false
         });
         updater.Update(new TileNotification(doc));
     }
     catch (Exception)
     {
         // ignored
     }
 }
Example #4
0
            public static PlayList DataContractJsonDeSerialize(string json)
            {
                try
                {
                    var obj = JsonObject.Parse(json);
                    var list = new PlayList();
                    list.nowplay = int.Parse(obj["nowplay"].GetNumber().ToString());
                    var cyc = obj["cyc"].GetNumber().ToString();
                    switch (cyc)
                    {
                        case "0":list.cyc = cycling.单曲循环;break;
                        case "1": list.cyc = cycling.列表循环; break;
                        case "2": list.cyc = cycling.随机播放; break;
                        default:break;
                    }
                    list.SongList = new List<NowPlay>();
                    try
                    {
                        var songs = obj["SongList"].GetArray();
                        foreach (var song in songs)
                        {
                            var nowplay = new NowPlay();
                            nowplay.albumid = song.GetObject()["albumid"].GetString();
                            nowplay.title = song.GetObject()["title"].GetString();
                            nowplay.singername = song.GetObject()["singername"].GetString();
                            nowplay.url = song.GetObject()["url"].GetString();
                            nowplay.imgurl = song.GetObject()["imgurl"].GetString();
                            nowplay.pics = new List<string>();
                            try
                            {
                                var pics = song.GetObject()["pics"].GetArray();
                                foreach (var pic in pics)
                                {
                                    nowplay.pics.Add(pic.GetString());
                                }
                            }
                            catch (Exception)
                            {

                            }
                            list.SongList.Add(nowplay);
                        }
                    }
                    catch (Exception)
                    {
                        
                    }
                    return list;
                }
                catch (Exception)
                {
                    return null;
                }
            }
Example #5
0
 public static async Task SetNowPlay(NowPlay nowplay)
 {
     try
     {
         var json = Class.data.ToJsonData(nowplay);
         var datafolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Data");
         var nowplayfile = await datafolder.GetFileAsync("nowplay.json");
         await Windows.Storage.FileIO.WriteTextAsync(nowplayfile, json);
     }
     catch (Exception)
     {
         
     }
 }