internal async Task <Album> GetOnlineAlbumAsync(string id)
        {
            var querys = new ValueSet()
            {
                new KeyValuePair <string, object>("q", "online_music"),
                new KeyValuePair <string, object>("action", "album"),
                new KeyValuePair <string, object>("id", id)
            };
            var songResult = await OnlineMusicExtension.ExecuteAsync(querys);

            if (songResult is Album s)
            {
                return(s);
            }
            return(null);
        }
Exemple #2
0
        internal async Task <Song> GetOnlineSongAsync(string id)
        {
            var querys = new ValueSet()
            {
                new KeyValuePair <string, object>("q", "online_music"),
                new KeyValuePair <string, object>("action", "song"),
                new KeyValuePair <string, object>("id", id),
                new KeyValuePair <string, object>("bit_rate", Settings.Current.GetPreferredBitRate())
            };
            var songResult = await OnlineMusicExtension.ExecuteAsync(querys);

            if (songResult is Song s)
            {
                return(s);
            }
            return(null);
        }
Exemple #3
0
        internal async Task Search(string text)
        {
            if (OnlineMusicExtension != null)
            {
                _lastQuery = string.Copy(text);
                var s = string.Copy(_lastQuery);

                var job = ThreadPool.RunAsync(async work =>
                {
                    var querys = new ValueSet()
                    {
                        new KeyValuePair <string, object>("q", "online_music"),
                        new KeyValuePair <string, object>("action", "search"),
                        new KeyValuePair <string, object>("keyword", text)
                    };
                    var dd = CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, async() =>
                    {
                        await Task.Delay(200);
                        MainPage.Current.ShowAutoSuggestPopup();
                    });
                    var webResult = await OnlineMusicExtension.ExecuteAsync(querys);
                    if (webResult is IEnumerable <OnlineMusicItem> items)
                    {
                        if (MainPage.Current.CanAdd && s.Equals(_lastQuery, StringComparison.Ordinal))
                        {
                            await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                            {
                                lock (MainPage.Current.Lockable)
                                {
                                    if (SearchItems.Count > 0 && SearchItems[0].InnerType == MediaType.Placeholder)
                                    {
                                        SearchItems.Clear();
                                    }
                                    foreach (var item in items.Reverse())
                                    {
                                        SearchItems.Insert(0, new GenericMusicItemViewModel(item));
                                    }
                                    MainPage.Current.HideAutoSuggestPopup();
                                }
                            });
                        }
                    }
                });
            }

            var result = await FileReader.Search(text);

            if (MainPage.Current.CanAdd && !result.IsNullorEmpty())
            {
                await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                {
                    lock (MainPage.Current.Lockable)
                    {
                        if (SearchItems.Count > 0 && SearchItems[0].InnerType == MediaType.Placeholder)
                        {
                            SearchItems.Clear();
                        }
                        foreach (var item in result)
                        {
                            SearchItems.Add(new GenericMusicItemViewModel(item));
                        }
                    }
                    MainPage.Current.HideAutoSuggestPopup();
                });
            }
        }