コード例 #1
0
        public Task FillAudioList(FillAudioBody argument)
        {
            return(Task.Run(() =>
            {
                int startIndex = 0;
                if (argument.Type != FillAudioType.AddMore)
                {
                    TabPageBodies[argument.Index].PlayList.Clear();
                    switch (argument.Type)
                    {
                    case FillAudioType.UserAudio:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.Get(UserId: argument.UserId, AlbumId: argument.AlbumId, Count: AudioGetStep));
                        TabPageBodies[argument.Index].User = MainApi.User.Get(argument.UserId);
                        TabPageBodies[argument.Index].TotalAudios = MainApi.Audio.Count(argument.UserId);
                        TabPageBodies[argument.Index].AlbumList = MainApi.Audio.GetAlbums(argument.UserId).ToList();
                        break;

                    case FillAudioType.GroupAudio:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.GetGroup((long)argument.GroupId, AlbumId: argument.AlbumId, Count: AudioGetStep));
                        TabPageBodies[argument.Index].Group = MainApi.Group.GetById((long)argument.GroupId);
                        TabPageBodies[argument.Index].TotalAudios = MainApi.Audio.Count(0 - argument.GroupId);
                        TabPageBodies[argument.Index].AlbumList = MainApi.Audio.GetAlbums(0 - argument.GroupId).ToList();
                        break;

                    case FillAudioType.Search:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.Search(argument.SearchQuerry, out TabPageBodies[argument.Index].TotalAudios, (bool)argument.IsArtist, Count: AudioGetStep));
                        break;

                    case FillAudioType.Recommendation:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.GetRecommended(UserId: argument.UserId, Count: AudioGetStep));
                        break;

                    case FillAudioType.Popular:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.GetPopular(AudioGetStep));
                        break;

                    case FillAudioType.Playlist:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.Player.GetPlaylist());
                        break;

                    case FillAudioType.Cache:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.GetCache(Count: AudioGetStep));
                        TabPageBodies[argument.Index].TotalAudios = MainApi.Audio.CacheCount();
                        break;
                    }
                    TabPageBodies[argument.Index].LastAudioAction = argument;
                }
                else
                {
                    startIndex = TabPageBodies[argument.Index].PlayList.Count;
                    var lastArgument = TabPageBodies[argument.Index].LastAudioAction;

                    switch (lastArgument.Type)
                    {
                    case FillAudioType.UserAudio:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.Get(lastArgument.UserId, lastArgument.AlbumId, AudioGetStep, startIndex));
                        break;

                    case FillAudioType.GroupAudio:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.GetGroup((long)lastArgument.GroupId, lastArgument.AlbumId, AudioGetStep, startIndex));
                        break;

                    case FillAudioType.Search:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.Search(lastArgument.SearchQuerry, (bool)lastArgument.IsArtist, AudioGetStep, startIndex));
                        break;

                    case FillAudioType.Recommendation:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.GetRecommended(UserId: argument.UserId, Count: AudioGetStep, Offset: startIndex));
                        break;

                    case FillAudioType.Popular:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.GetPopular(AudioGetStep, Offset: startIndex));
                        break;

                    case FillAudioType.Playlist:
                        break;

                    case FillAudioType.Cache:
                        TabPageBodies[argument.Index].PlayList.AddRange(MainApi.Audio.GetCache(Count: AudioGetStep, Offset: startIndex));
                        break;
                    }
                }

                var KnownBitrate = new Dictionary <int, string>();

                for (int i = startIndex; i < TabPageBodies[argument.Index].PlayList.Count; i++)
                {
                    var predicate = "{0} == {1} AND {2} == {3}";
                    var resp = MainApi.DB.Select(DBTable.AudioRate, string.Format(predicate, DBTable.AudioRate.Columns[1].Name, TabPageBodies[argument.Index].PlayList[i].Id, DBTable.AudioRate.Columns[2].Name, TabPageBodies[argument.Index].PlayList[i].OwnerId));
                    if (resp.Count > 0)
                    {
                        long rate = Convert.ToInt64((resp[0] as object[]).Last());
                        if (rate != 0)
                        {
                            KnownBitrate.Add(i, (rate * 8 / 1000 / TabPageBodies[argument.Index].PlayList[i].Duration) + "kb/s");
                        }
                    }
                }

                if (AudioListUpdater != null)
                {
                    AudioListUpdater(this, new FillAudioListEventArgs(TabPageBodies[argument.Index], startIndex, KnownBitrate));
                }
            }));
        }
コード例 #2
0
 public AudioTabPageBody()
 {
     LastAudioAction = new FillAudioBody();
     PlayList        = new List <VkNet.Model.Attachments.Audio>();
     AlbumList       = new List <VkNet.Model.AudioAlbum>();
 }