Exemple #1
0
        public void PlayAudio(VkAudioAttachment audio)
        {
            BackgroundMediaPlayer.Current.SetUriSource(new Uri(audio.Url));
            BackgroundMediaPlayer.Current.Play();

            _positionTimer.Start();
        }
Exemple #2
0
        public static VkWallEntry FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }
            VkWallEntry vkWallEntry = new VkWallEntry();

            vkWallEntry.Id = json["id"].Value <double>();
            if (json["attachments"] != null)
            {
                vkWallEntry.Attachments = new List <VkAttachment>();
                using (IEnumerator <JToken> enumerator = json["attachments"].AsEnumerable().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        JToken current = enumerator.Current;
                        string text;
                        if ((text = current["type"].Value <string>()) != null && text == "audio")
                        {
                            vkWallEntry.Attachments.Add(VkAudioAttachment.FromJson(current["audio"]));
                        }
                    }
                }
            }
            return(vkWallEntry);
        }
        private async Task <List <VkAudioAttachment> > GetAudioList(IProgress <int> progress, CancellationToken token)
        {
            if (Tracks == null)
            {
                return(null);
            }

            var result        = new List <VkAudioAttachment>();
            int requestsCount = 0;

            foreach (var audio in Tracks)
            {
                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                if (audio.Source == null)
                {
                    VkAudio vkAudio = null;
                    try
                    {
                        vkAudio = await DataService.GetAudioByArtistAndTitle(audio.Artist, audio.Title);
                    }
                    catch (Exception ex)
                    {
                        LoggingService.Log(ex);
                    }

                    if (vkAudio != null)
                    {
                        var audioAttachment = new VkAudioAttachment();
                        audioAttachment.Id      = long.Parse(vkAudio.Id);
                        audioAttachment.OwnerId = vkAudio.OwnerId;
                        result.Add(audioAttachment);
                    }
                    else
                    {
                        LoggingService.Log("Failed to find audio " + audio.Artist + " - " + audio.Title);
                    }

                    requestsCount++;

                    if (requestsCount >= 2) //не больше 2-х запросов в секунду
                    {
                        requestsCount = 0;
                        await Task.Delay(1000);
                    }
                }
                else
                {
                    var audioAttachment = new VkAudioAttachment();
                    audioAttachment.Id      = long.Parse(audio.Id);
                    audioAttachment.OwnerId = audio.OwnerId;
                    result.Add(audioAttachment);
                }

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                progress.Report(1);
            }

            return(result);
        }
Exemple #4
0
        public static VkNewsEntry FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }
            VkNewsEntry vkNewsEntry = new VkNewsEntry();

            if (json["post_id"] != null)
            {
                vkNewsEntry.Id = json["post_id"].Value <long>();
            }
            if (json["type"] != null)
            {
                vkNewsEntry.Type = json["type"].Value <string>();
            }
            if (json["source_id"] != null)
            {
                vkNewsEntry.SourceId = json["source_id"].Value <long>();
            }
            if (json["date"] != null)
            {
                vkNewsEntry.Date = DateTimeExtensions.UnixTimeStampToDateTime((double)json["date"].Value <long>());
            }
            if (json["text"] != null)
            {
                vkNewsEntry.Text = json["text"].Value <string>();
                vkNewsEntry.Text = vkNewsEntry.Text.Replace("<br>", Environment.NewLine);
            }
            if (json["attachments"] != null)
            {
                vkNewsEntry.Attachments = new List <VkAttachment>();
                using (IEnumerator <JToken> enumerator = json["attachments"].AsEnumerable().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        JToken current = enumerator.Current;
                        string text;
                        if ((text = current["type"].Value <string>()) != null)
                        {
                            if (!(text == "audio"))
                            {
                                if (text == "photo")
                                {
                                    vkNewsEntry.Attachments.Add(VkPhotoAttachment.FromJson(current["photo"]));
                                }
                            }
                            else
                            {
                                vkNewsEntry.Attachments.Add(VkAudioAttachment.FromJson(current["audio"]));
                            }
                        }
                    }
                }
            }
            if (json["comments"] != null)
            {
                vkNewsEntry.CommentsCount   = json["comments"]["count"].Value <long>();
                vkNewsEntry.CanWriteComment = (json["comments"]["can_post"].Value <int>() == 1);
            }
            return(vkNewsEntry);
        }
Exemple #5
0
        public static VkWallEntry FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }

            var result = new VkWallEntry();

            result.Id = json["id"].Value <double>();

            if (json["text"] != null)
            {
                result.Text = WebUtility.HtmlDecode(json["text"].Value <string>());
                result.Text = result.Text.Replace("<br>", Environment.NewLine);
            }

            if (json["from_id"] != null)
            {
                result.SourceId = json["from_id"].Value <long>();
            }

            if (json["date"] != null)
            {
                result.Date = DateTimeExtensions.UnixTimeStampToDateTime(json["date"].Value <long>());
            }

            if (json["attachments"] != null)
            {
                result.Attachments = new List <VkAttachment>();

                foreach (var a in json["attachments"])
                {
                    switch (a["type"].Value <string>())
                    {
                    case "audio":
                        result.Attachments.Add(VkAudioAttachment.FromJson(a["audio"]));
                        break;

                    case "photo":
                        result.Attachments.Add(VkPhotoAttachment.FromJson(a["photo"]));
                        break;
                    }
                }
            }

            if (json["copy_history"] != null)
            {
                result.CopyHistory = new List <VkWallEntry>();

                foreach (var p in json["copy_history"])
                {
                    try
                    {
                        var post = VkWallEntry.FromJson(p);
                        if (post != null)
                        {
                            result.CopyHistory.Add(post);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                    }
                }
            }

            return(result);
        }