Пример #1
0
 void DownLoad()
 {
     DependencyService.Get <IToast>().ShortAlert("后台下载中");
     Task.Run(() => {
         var downloadManager = Plugin.DownloadManager.CrossDownloadManager.Current;
         string ids          = string.Join(",", MusicPlayList.playlist.trackIds.Select(q => q.id));
         var r = CloudMusicApiHelper.GetSong(ids, Models.ENUM.CouldMusicBpsType.high);
         if (r != null)
         {
             if (r.code == 200)
             {
                 for (int i = 0; i < r.data.Count(); i++)
                 {
                     if (r.data[i].url == null)
                     {
                         continue;
                     }
                     Dictionary <string, string> filedic = new Dictionary <string, string>();
                     filedic["name"] = MusicPlayList.playlist.tracks[i].name;
                     filedic["type"] = r.data[i].encodeType;
                     var file        = downloadManager.CreateDownloadFile(r.data[i].url, filedic);
                     downloadManager.Start(file);
                 }
             }
         }
     });
 }
Пример #2
0
 private void PlaytapGesture_Tapped(object sender, EventArgs e)
 {
     Task.Run(() => {
         var q = CloudMusicApiHelper.GetVideoUrls(((MusicEventModel.friendEvent)BindingContext).Conent.video.videoId);
         if (q != null)
         {
             Device.BeginInvokeOnMainThread(() => {
                 videocover.IsVisible = false;
                 videoinfo.IsVisible  = false;
                 playbtn.IsVisible    = false;
                 videoplayer.BatchBegin();
                 videoplayer.IsVisible = true;
                 videoplayer.Source    = new UriVideoSource {
                     Uri = q.urls[0].url
                 };
                 videoplayer.BatchCommit();
                 videoplayer.Play();
                 if (Device.RuntimePlatform == Device.Android)
                 {
                     this.ForceUpdateSize();
                 }
             });
         }
         else
         {
             Device.BeginInvokeOnMainThread(() => DependencyService.Get <IToast>().ShortAlert("播放失败"));
         }
     });
 }
 void GetPersonalFM()
 {
     IsBusy = true;
     Task.Run(() => {
         var s = CloudMusicApiHelper.PersonalFM(offset);
         if (s != null)
         {
             if (s.code == 200)
             {
                 if (personalFm == null)
                 {
                     personalFm = s;
                     ChangeMusic(0);
                 }
                 else
                 {
                     foreach (var q in s.data)
                     {
                         personalFm.data.Add(q);
                     }
                 }
                 offset += 3;
             }
         }
         IsBusy = false;
     });
 }
Пример #4
0
 void ListViewLoadMore()
 {
     IsBusy = true;
     Task.Run(() => {
         var comment = CloudMusicApiHelper.GetMvComment("50", mvid, Commentpage);
         if (comment != null)
         {
             if (MvComment == null)
             {
                 MvComment    = comment;
                 CommentCount = comment.total;
             }
             else
             if (comment.code == 200)
             {
                 foreach (var q in comment.comments)
                 {
                     MvComment.comments.Add(q);
                 }
             }
             IsBusy       = false;
             Commentpage += 50;
         }
     });
 }
 void LikeSongClicked()
 {
     Task.Run(() => {
         var r = CloudMusicApiHelper.LikeSong(NowSongInfo.id.ToString(), !NowSongInfo.starred);
         if (r != "err")
         {
             likeIcon = !NowSongInfo.starred? "PlayHeart_red": "PlayHeart";
         }
     });
 }
        void ChangeMusic(int s)
        {
            ImageUrl    = personalFm.data[s].album.picUrl;
            NowSongInfo = personalFm.data[s];

            likeIcon      = personalFm.data[s].starred? "PlayHeart_red" : "PlayHeart";
            NowDuration   = new TimeSpan(0);
            MusicDuration = TimeSpan.FromMilliseconds(personalFm.data[s].duration);
            Task.Run(async() =>
            {
                MusicInfo result = CloudMusicApiHelper.GetSong(personalFm.data[s].id.ToString(), Models.ENUM.CouldMusicBpsType.high);
                if (result != null)
                {
                    musicInfo = result;
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(result.data[0].url))
                        {
                            await CrossMediaManager.Current.Play($"https://music.163.com/song/media/outer/url?id={personalFm.data[s].id}.mp3");
                        }
                        else
                        {
                            Device.BeginInvokeOnMainThread(() => DependencyService.Get <IToast>().ShortAlert("没有版权"));
                        }
                        if (s + 2 >= personalFm.data.Count)
                        {
                            GetPersonalFM();
                        }
                    }
                    catch { }
                    var r = CloudMusicApiHelper.GetSongComment("50", personalFm.data[s].id.ToString(), 0);
                    if (result != null)
                    {
                        int cCount = r.total;
                        if (cCount < 1000)
                        {
                            CommentCount = cCount.ToString();
                        }
                        else if (cCount > 1000 & cCount < 10000)
                        {
                            CommentCount = "999+";
                        }
                        else if (cCount > 10000 & cCount < 100000)
                        {
                            CommentCount = "1w+";
                        }
                        else if (cCount > 100000)
                        {
                            CommentCount = "10w+";
                        }
                    }
                }
            });
        }
Пример #7
0
 void GetMvInfo()
 {
     Task.Run(() =>
     {
         var mvinfo = CloudMusicApiHelper.GetMusicVideo(mvid);
         Artists    = new ObservableCollection <ArtistsInfo>();
         if (mvinfo != null)
         {
             if (mvinfo.code == 200)
             {
                 Device.BeginInvokeOnMainThread(() => MvInfo = mvinfo);
                 string videourl = string.Empty;
                 if (!string.IsNullOrWhiteSpace(mvinfo.data.brs._1080))
                 {
                     videourl = mvinfo.data.brs._1080;
                 }
                 else if (!string.IsNullOrWhiteSpace(mvinfo.data.brs._720))
                 {
                     videourl = mvinfo.data.brs._720;
                 }
                 else if (!string.IsNullOrWhiteSpace(mvinfo.data.brs._480))
                 {
                     videourl = mvinfo.data.brs._480;
                 }
                 else if (!string.IsNullOrWhiteSpace(mvinfo.data.brs._240))
                 {
                     videourl = mvinfo.data.brs._240;
                 }
                 if (!string.IsNullOrWhiteSpace(videourl))
                 {
                     UriSource = new UriVideoSource {
                         Uri = videourl
                     }
                 }
                 ;
             }
         }
         var _artists = new ObservableCollection <ArtistsInfo>();
         foreach (var q in mvinfo.data.artists)
         {
             var artistsInfo = CloudMusicApiHelper.GetArtist(q.id.ToString());
             if (artistsInfo != null)
             {
                 if (artistsInfo.code == 200)
                 {
                     _artists.Add(artistsInfo);
                 }
             }
         }
         Artists = _artists;
     });
     GetMiSiMv();
     ListViewLoadMore();
 }
 void GetPersonalized()
 {
     Task.Run(() => {
         var r = CloudMusicApiHelper.GetPersonalized(6);
         if (r != null)
         {
             if (r.code == 200)
             {
                 personalized = r;
             }
         }
     });
 }
 void GetSiMiUsers(string id)
 {
     Task.Run(() => {
         var r = CloudMusicApiHelper.GetSiMiUsers(id);
         if (r != null)
         {
             if (r.code == 200)
             {
                 simiUsers = r;
             }
         }
     });
 }
 void GetNewestAlbum()
 {
     Task.Run(() => {
         var r = CloudMusicApiHelper.GetNewAlbums(3, 0);
         if (r != null)
         {
             if (r.code == 200)
             {
                 newAlbums = r;
             }
         }
     });
 }
 void GetSubscriptionCount()
 {
     Task.Run(() => {
         var r = CloudMusicApiHelper.SubscriptionCount();
         if (r != null)
         {
             if (r.code == 200)
             {
                 subscriptionCount = r;
             }
         }
     });
 }
 void Getbanners()
 {
     Task.Run(() => {
         var r = CloudMusicApiHelper.GetBanners();
         if (r != null)
         {
             if (r.code == 200)
             {
                 mainBanner = r;
             }
         }
     });
 }
 void GetArtistDetail()
 {
     Task.Run(() => {
         var r = CloudMusicApiHelper.ArtistDetial(artistid);
         if (r != null)
         {
             if (r.code == 200)
             {
                 artistDetail = r;
             }
         }
     });
 }
 void GetSuggest()
 {
     Task.Run(() =>
     {
         var suggest = CloudMusicApiHelper.MobileSearchSuggest(KeyWords);
         if (suggest != null)
         {
             if (suggest.code == 200)
             {
                 MobileSearchSuggest = suggest;
             }
         }
     });
 }
Пример #15
0
 void GetMiSiMv()
 {
     Task.Run(() =>
     {
         var simimv = CloudMusicApiHelper.GetSiMiMusicVideo(mvid);
         if (simimv != null)
         {
             if (simimv.code == 200)
             {
                 SiMiMvInfo = simimv;
             }
         }
     });
 }
 void GetNewestSongs()
 {
     Task.Run(() => {
         var r = CloudMusicApiHelper.GetNewSongs();
         if (r != null)
         {
             if (r.code == 200)
             {
                 r.result.RemoveRange(3, r.result.Count - 3);
                 topNewSongs = r;
             }
         }
     });
 }
Пример #17
0
 void GetEventData()
 {
     offset    = 0;
     IsRefresh = true;
     Task.Run(() => {
         var r = CloudMusicApiHelper.GetFriendEvents(offset);
         if (r != null)
         {
             if (r.code == 200)
             {
                 friendEvents = r;
             }
         }
         IsRefresh = false;
     });
 }
 void AutoCompleteSelectionChanged(object e)
 {
     Task.Run(() =>
     {
         Syncfusion.SfAutoComplete.XForms.SelectionChangedEventArgs items = e as Syncfusion.SfAutoComplete.XForms.SelectionChangedEventArgs;
         var i    = items.AddedItems as MobileSearchSuggestModel.Allmatch;
         var info = CloudMusicApiHelper.Search(i.keyword, 30, 0, currentType);
         if (info != null)
         {
             if (info.code == 200)
             {
                 SearchResult = info;
             }
         }
     });
 }
Пример #19
0
 void GetPlayListData()
 {
     IsBusy = true;
     Task.Run(() => {
         var s = CloudMusicApiHelper.PlayListDetial(playlistId);
         if (s != null)
         {
             if (s.code == 200)
             {
                 MusicPlayList = s;
                 if (string.IsNullOrWhiteSpace(BgPic))
                 {
                     BgPic = s.playlist.coverImgUrl;
                 }
             }
         }
         IsBusy = false;
     });
 }
 void GetRecommendSongs()
 {
     Task.Run(() => {
         var r = CloudMusicApiHelper.GetRecommendSongs();
         if (r != null)
         {
             if (r.code == 200)
             {
                 recommendSongs = r;
                 if (recommendSongs.recommend.Count > 0)
                 {
                     GetSiMiUsers(recommendSongs.recommend[0].id.ToString());
                     //ThemeColors colors= await DependencyService.Get<IPalette>().GetColorAsync(new UriImageSource {Uri=new Uri(recommendSongs.recommend[0].album.picUrl)});
                     //MainColor = colors.MainColor;
                 }
             }
         }
     });
 }
Пример #21
0
 void LoadVideos()
 {
     offset = 0;
     IsBusy = true;
     Task.Run(() => {
         var o = Enum.GetValues(typeof(Models.ENUM.CouldMusicVideoGroup));
         int c = ran.Next(o.Length);
         var r = CloudMusicApiHelper.GetVideoInfoByGroup((Models.ENUM.CouldMusicVideoGroup)o.GetValue(c), 20, offset);
         if (r != null)
         {
             if (r.code == 200)
             {
                 VideoInfo = r;
             }
         }
         IsLoading = false;
         IsBusy    = false;
     });
 }
 void LoginClick()
 {
     Task.Run(() => {
         var r = CloudMusicApiHelper.Login(username, password);
         if (r != null)
         {
             if (r.code == 200)
             {
                 Xamarin.Essentials.Preferences.Set("userid", r.profile.userId);
                 Xamarin.Essentials.Preferences.Set("username", r.account.userName);
                 Device.BeginInvokeOnMainThread(async() => await NavigationService.GoBackAsync());
             }
             else
             {
                 Device.BeginInvokeOnMainThread(() => DependencyService.Get <IToast>().ShortAlert(r.msg));
             }
         }
     });
 }
Пример #23
0
 void ListViewLoadMore()
 {
     offset += 50;
     IsBusy  = true;
     Task.Run(() => {
         var r = CloudMusicApiHelper.GetFriendEvents(offset);
         if (r != null)
         {
             if (r.code == 200)
             {
                 foreach (var q in r.friendevent)
                 {
                     friendEvents.friendevent.Add(q);
                 }
                 IsBusy = false;
             }
         }
         ;
     });
 }
Пример #24
0
 private void Login(string user, string pd)
 {
     Task.Run(() =>
     {
         var r = CloudMusicApiHelper.Login(user, pd);
         if (r != null)
         {
             if (r.code == 200)
             {
                 Xamarin.Essentials.Preferences.Set("userid", r.profile.userId);
                 Xamarin.Essentials.Preferences.Set("username", r.account.userName);
                 Device.BeginInvokeOnMainThread(async() => await NavigationService.NavigateAsync("/NavigationPage/MusicHomePage?selectedTab=MusicDiscoverPage"));
             }
         }
         else
         {
             Device.BeginInvokeOnMainThread(() => DependencyService.Get <IToast>().ShortAlert("错误"));
         }
     });
 }
 void SearchAll()
 {
     IsBusy = true;
     Task.Run(() =>
     {
         offset   = 0;
         var info = CloudMusicApiHelper.SearchAll(KeyWords, 30, offset);
         if (info != null)
         {
             if (info.code == 200)
             {
                 if (SearchResult == null)
                 {
                     SearchAllResult = info;
                 }
                 offset += 30;
                 IsBusy  = false;
             }
         }
     });
 }
        void GetUserPlayLists()
        {
            ObservableCollection <Playlist> userpl = new ObservableCollection <Playlist>();
            ObservableCollection <Playlist> subpl  = new ObservableCollection <Playlist>();

            Task.Run(() => {
                try
                {
                    string id = Xamarin.Essentials.Preferences.Get("userid", 76074798).ToString();
                    var r     = CloudMusicApiHelper.UserPlayLists(id);
                    if (r != null)
                    {
                        if (r.code == 200)
                        {
                            var userlist = r.playlist.Where(q => !q.subscribed);
                            var sublist  = r.playlist.Where(q => q.subscribed);
                            foreach (var q in userlist)
                            {
                                userpl.Add(q);
                            }
                            foreach (var q in sublist)
                            {
                                subpl.Add(q);
                            }
                            Device.BeginInvokeOnMainThread(() => {
                                userPlayLists       = userpl;
                                subscribedPlayLists = subpl;
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            });
        }
Пример #27
0
 void LoadMoreVideo()
 {
     //offset += 20;
     IsBusy = true;
     Task.Run(() => {
         var o = Enum.GetValues(typeof(Models.ENUM.CouldMusicVideoGroup));
         int c = ran.Next(o.Length);
         var r = CloudMusicApiHelper.GetVideoInfoByGroup((Models.ENUM.CouldMusicVideoGroup)o.GetValue(c), 20, offset);
         if (r != null)
         {
             if (r.code == 200)
             {
                 if (VideoInfo != null)
                 {
                     foreach (var q in r.datas)
                     {
                         VideoInfo.datas.Add(q);
                     }
                 }
             }
         }
         IsBusy = false;
     });
 }
        void ListViewLoadMore()
        {
            IsBusy = true;
            Task.Run(() => {
                var info = CloudMusicApiHelper.Search(KeyWords, 30, offset, currentType);
                if (info != null)
                {
                    if (info.code == 200)
                    {
                        switch (currentType)
                        {
                        case CloudMusicSearchType.SingleSong:
                            foreach (var q in info.result.songs)
                            {
                                SearchResult.result.songs.Add(q);
                            }
                            break;

                        case CloudMusicSearchType.Video:
                            foreach (var q in info.result.videos)
                            {
                                SearchResult.result.videos.Add(q);
                            }
                            break;

                        case CloudMusicSearchType.Singer:
                            foreach (var q in info.result.artists)
                            {
                                SearchResult.result.artists.Add(q);
                            }
                            break;

                        case CloudMusicSearchType.Album:
                            foreach (var q in info.result.albums)
                            {
                                SearchResult.result.albums.Add(q);
                            }
                            break;

                        case CloudMusicSearchType.PlayList:
                            foreach (var q in info.result.playlists)
                            {
                                SearchResult.result.playlists.Add(q);
                            }
                            break;

                        case CloudMusicSearchType.FM:
                            foreach (var q in info.result.djRadios)
                            {
                                SearchResult.result.djRadios.Add(q);
                            }
                            break;

                        case CloudMusicSearchType.User:
                            foreach (var q in info.result.userprofiles)
                            {
                                SearchResult.result.userprofiles.Add(q);
                            }
                            break;

                        case CloudMusicSearchType.MV:
                            foreach (var q in info.result.mvs)
                            {
                                SearchResult.result.mvs.Add(q);
                            }
                            break;
                        }

                        offset += 30;
                    }
                }
                IsBusy = false;
            });
        }