Beispiel #1
0
        private async Task <ResponseInfo> GetYoutubeSongs(JToken parameters)
        {
            var searchTerm = parameters["searchTerm"].ToObject <string>();

            try
            {
                var requestCache = Locator.Current.GetService <IBlobCache>(BlobCacheKeys.RequestCacheContract);
                var songFinder   = new YoutubeSongFinder(requestCache);

                IReadOnlyList <YoutubeSong> songs = await songFinder.GetSongsAsync(searchTerm);

                // Cache the latest YouTube search request, so we can find the songs by GUID when we
                // add one to the playlist later
                this.lastYoutubeRequest = songs;

                JObject content = MobileHelper.SerializeSongs(songs);

                return(CreateResponse(ResponseStatus.Success, content));
            }

            catch (NetworkSongFinderException)
            {
                return(CreateResponse(ResponseStatus.Failed, "Couldn't retrieve any YouTube songs"));
            };
        }
Beispiel #2
0
        private async Task PushPlaylist(Playlist playlist, AudioPlayerState state)
        {
            JObject content = MobileHelper.SerializePlaylist(playlist, state,
                                                             await this.library.CurrentPlaybackTime.FirstAsync(),
                                                             await this.library.TotalTime.FirstAsync());

            NetworkMessage message = CreatePushMessage(PushAction.UpdateCurrentPlaylist, content);

            await this.SendMessage(message);
        }
Beispiel #3
0
        private async Task <ResponseInfo> GetCurrentPlaylist(JToken dontCare)
        {
            Playlist         playlist      = this.library.CurrentPlaylist;
            AudioPlayerState playbackState = await this.library.PlaybackState.FirstAsync();

            TimeSpan currentTime = await this.library.CurrentPlaybackTime.FirstAsync();

            TimeSpan totalTime = await this.library.TotalTime.FirstAsync();

            JObject content = MobileHelper.SerializePlaylist(playlist, playbackState, currentTime, totalTime);

            return(CreateResponse(ResponseStatus.Success, null, content));
        }
Beispiel #4
0
        private async Task <ResponseInfo> GetLibraryContent(JToken dontCare)
        {
            JObject content = await Task.Run(() => MobileHelper.SerializeSongs(this.library.Songs));

            return(CreateResponse(ResponseStatus.Success, null, content));
        }