Example #1
0
        public void AddAudioToList(List <VkNet.Model.Attachments.Audio> audios,
                                   ObservableCollection <OneAudioViewModel> musicList, bool fromSearch = false)
        {
            //MusicList = new ObservableCollection<AudioList>();
            musicList.Clear();
            //if (fromSearch)
            //{
            //    bool IncludeOwn = false;
            //    int startValue = 0;
            //    for (int i = 0; i < SearchAudios.Count; i++)
            //    {
            //        foreach (var ownaudio in Audio)
            //        {
            //            if (ownaudio.AccessKey == SearchAudios[i].AccessKey)
            //            {
            //                if (!IncludeOwn)
            //                {
            //                    IncludeOwn = true;
            //                    //MusicList.Add("               Ваши аудиозаписи:");
            //                }
            //                MusicList.Add(new AudioList(SearchAudios[i]));
            //                startValue++;
            //            }
            //        }
            //    }
            //    //if (startValue != 0)
            //    //    MusicList.Add("               Все аудиозаписи:");
            //    for (int j = startValue; j < SearchAudios.Count; j++)
            //    {
            //        MusicList.Add(new AudioList(SearchAudios[j]));
            //    }
            //    return;
            //}
            foreach (var audio in audios)
            {
                if (audio.Url == null)
                {
                    continue;
                }

                string imageSource = audio.Album?.Thumb?.Photo270 ?? "/Images/ImageMusic.png";

                musicList.Add(new OneAudioViewModel()
                {
                    ImageSourseString = imageSource,
                    Artist            = audio.Artist,
                    Title             = audio.Title,
                    Duration          = Decoder.ConvertTimeToString(audio.Duration),
                    Width             = 800,
                    Url       = Decoder.DecodeAudioUrl(audio.Url).ToString(),
                    Durration = audio.Duration
                });
            }
        }
Example #2
0
        public async void AddAudioToListAsync(List <VkNet.Model.Attachments.Audio> audios,
                                              SourceList <OneAudioViewModel> list, double width = 800, long id = -1)
        {
            await Task.Factory.StartNew(() =>
            {
                if (id != -1)
                {
                    audios = ApiDatas.Api.Audio.Get(new AudioGetParams()
                    {
                        OwnerId = id
                    }).ToList();
                }

                foreach (var audio in audios)
                {
                    if (audio.Url == null)
                    {
                        continue;
                    }

                    string imageSource = "/Images/ImageMusic.png";
                    try
                    {
                        imageSource = audio.Album?.Thumb?.Photo270;
                    }
                    catch
                    {
                        // ignored
                    }

                    list.Add(new OneAudioViewModel()
                    {
                        ImageSourseString = imageSource,
                        Artist            = audio.Artist,
                        Title             = audio.Title,
                        Duration          = Decoder.ConvertTimeToString(audio.Duration),
                        Width             = width,
                        Url       = Decoder.DecodeAudioUrl(audio.Url).ToString(),
                        Durration = audio.Duration
                    });
                }
            });
        }