Beispiel #1
0
        public async Task HandleProtocolAsync(string path)
        {
            LoggingService.Log(LoggingService.LogType.Debug, "Performing protocol work using path of " + path);


            if (!string.IsNullOrEmpty(path))
            {
                try
                {
                    if (path == "playUserLikes" || path == "shufflePlayUserLikes")
                    {
                        if (SoundByteV3Service.Current.IsServiceConnected(ServiceType.SoundCloud))
                        {
                            // Navigate to the now playing screen
                            RootFrame.Navigate(typeof(NowPlayingView));

                            // Get and load the user liked items
                            var userLikes = new SoundByteCollection <LikeSoundCloudSource, BaseTrack>();
                            userLikes.Source.User = SoundByteV3Service.Current.GetConnectedUser(ServiceType.SoundCloud);

                            // Loop through loading all the likes
                            while (userLikes.HasMoreItems)
                            {
                                await userLikes.LoadMoreItemsAsync(50);
                            }

                            // Play the list of items
                            await PlaybackService.Instance.StartModelMediaPlaybackAsync(userLikes, path == "shufflePlayUserLikes");

                            return;
                        }
                    }

                    if (path == "playUserStream")
                    {
                        if (SoundByteV3Service.Current.IsServiceConnected(ServiceType.SoundCloud))
                        {
                            // Navigate to the now playing screen
                            RootFrame.Navigate(typeof(NowPlayingView));

                            // Get and load the user liked items
                            var userStream = new SoundByteCollection <StreamSoundCloudSource, GroupedItem>();

                            // Counter so we don't get an insane amount of items
                            var i = 0;

                            // Grab all the users stream / 5 items
                            while (userStream.HasMoreItems && i <= 5)
                            {
                                i++;
                                await userStream.LoadMoreItemsAsync(50);
                            }

                            // Play the list of items
                            await PlaybackService.Instance.StartPlaylistMediaPlaybackAsync(
                                userStream.Where(x => x.Track != null).Select(x => x.Track).ToList());

                            return;
                        }
                    }

                    var parser = DeepLinkParser.Create(path);

                    var section = parser.Root.Split('/')[0].ToLower();
                    var page    = parser.Root.Split('/')[1].ToLower();

                    await App.SetLoadingAsync(true);

                    if (section == "core")
                    {
                        switch (page)
                        {
                        case "track":

                            BaseTrack track = null;

                            switch (parser["service"])
                            {
                            case "soundcloud":
                                track = (await SoundByteV3Service.Current.GetAsync <SoundCloudTrack>(ServiceType.SoundCloud, $"/tracks/{parser["id"]}")).ToBaseTrack();
                                break;

                            case "youtube":
                                break;

                            case "fanburst":
                                track = (await SoundByteV3Service.Current.GetAsync <FanburstTrack>(ServiceType.Fanburst, $"/videos/{parser["id"]}")).ToBaseTrack();
                                break;
                            }

                            if (track != null)
                            {
                                var startPlayback =
                                    await PlaybackService.Instance.StartPlaylistMediaPlaybackAsync(new List <BaseTrack> {
                                    track
                                });

                                if (!startPlayback.Success)
                                {
                                    await new MessageDialog(startPlayback.Message, "Error playing track.").ShowAsync();
                                }
                            }
                            break;

                        case "playlist":
                            var playlist =
                                await SoundByteV3Service.Current.GetAsync <SoundCloudPlaylist>(ServiceType.SoundCloud, $"/playlists/{parser["id"]}");

                            App.NavigateTo(typeof(PlaylistView), playlist.ToBasePlaylist());
                            return;

                        case "user":
                            var user = await SoundByteV3Service.Current.GetAsync <SoundCloudUser>(ServiceType.SoundCloud, $"/users/{parser["id"]}");

                            App.NavigateTo(typeof(UserView), user.ToBaseUser());
                            return;

                        case "changelog":
                            App.NavigateTo(typeof(WhatsNewView));
                            return;
                        }
                    }
                }
                catch (Exception)
                {
                    await new MessageDialog("The specified protocol is not correct. App will now launch as normal.")
                    .ShowAsync();
                }
                await App.SetLoadingAsync(false);
            }

            RootFrame.Navigate(SoundByteV3Service.Current.IsServiceConnected(ServiceType.SoundCloud)
                ? typeof(SoundCloudStreamView)
                : typeof(ExploreView));
        }
Beispiel #2
0
        public async Task HandleProtocolAsync(string path)
        {
            LoggingService.Log(LoggingService.LogType.Debug, "Performing protocol work using path of " + path);

            if (!string.IsNullOrEmpty(path))
            {
                try
                {
                    if (path == "playUserLikes" || path == "shufflePlayUserLikes")
                    {
                        if (SoundByteService.Current.IsServiceConnected(ServiceType.SoundCloud))
                        {
                            // Navigate to the now playing screen
                            RootFrame.Navigate(typeof(NowPlayingView));

                            // Get and load the user liked items
                            var userLikes = new SoundByteCollection <SoundCloudLikeSource, BaseTrack>();
                            userLikes.Source.User = SoundByteService.Current.GetConnectedUser(ServiceType.SoundCloud);

                            // Loop through loading all the likes
                            while (userLikes.HasMoreItems)
                            {
                                await userLikes.LoadMoreItemsAsync(50);
                            }

                            // Play the list of items
                            await BaseViewModel.PlayAllTracksAsync(userLikes, null, path == "shufflePlayUserLikes");

                            return;
                        }
                    }

                    if (path == "playUserStream")
                    {
                        if (SoundByteService.Current.IsServiceConnected(ServiceType.SoundCloud))
                        {
                            // Navigate to the now playing screen
                            RootFrame.Navigate(typeof(NowPlayingView));

                            // Get and load the user liked items
                            var userStream = new SoundByteCollection <SoundCloudStreamSource, GroupedItem>();

                            // Counter so we don't get an insane amount of items
                            var i = 0;

                            // Grab all the users stream / 5 items
                            while (userStream.HasMoreItems && i <= 5)
                            {
                                i++;
                                await userStream.LoadMoreItemsAsync(50);
                            }

                            // Play the list of items
                            var result = await PlaybackService.Instance.InitilizePlaylistAsync <DummyTrackSource>(
                                userStream.Where(x => x.Track != null).Select(x => x.Track).ToList());

                            if (result.Success)
                            {
                                await PlaybackService.Instance.StartTrackAsync();
                            }

                            return;
                        }
                    }

                    var parser = DeepLinkParser.Create(path);

                    var section = parser.Root?.Split('/')[0]?.ToLower();

                    await App.SetLoadingAsync(true);

                    if (section == "core")
                    {
                        var page = parser.Root?.Split('/')[1]?.ToLower();

                        switch (page)
                        {
                        case "track":

                            BaseTrack track = null;

                            switch (parser["service"])
                            {
                            case "soundcloud":
                                track = (await SoundByteService.Current.GetAsync <SoundCloudTrack>(ServiceType.SoundCloud, $"/tracks/{parser["id"]}")).Response.ToBaseTrack();
                                break;

                            case "youtube":
                                break;

                            case "fanburst":
                                track = (await SoundByteService.Current.GetAsync <FanburstTrack>(ServiceType.Fanburst, $"/videos/{parser["id"]}")).Response.ToBaseTrack();
                                break;
                            }

                            if (track != null)
                            {
                                var startPlayback =
                                    await PlaybackService.Instance.InitilizePlaylistAsync <DummyTrackSource>(new List <BaseTrack> {
                                    track
                                });

                                if (startPlayback.Success)
                                {
                                    await PlaybackService.Instance.StartTrackAsync();
                                }
                                else
                                {
                                    await NavigationService.Current.CallMessageDialogAsync(startPlayback.Message,
                                                                                           "Error playing track.");
                                }
                            }
                            break;

                        case "playlist":
                            var playlist =
                                await SoundByteService.Current.GetAsync <SoundCloudPlaylist>(ServiceType.SoundCloud, $"/playlists/{parser["id"]}");

                            App.NavigateTo(typeof(PlaylistView), playlist.Response.ToBasePlaylist());
                            return;

                        case "user":
                            var user = await SoundByteService.Current.GetAsync <SoundCloudUser>(ServiceType.SoundCloud, $"/users/{parser["id"]}");

                            App.NavigateTo(typeof(UserView), user.Response.ToBaseUser());
                            return;

                        case "changelog":
                            await NavigationService.Current.CallDialogAsync <WhatsNewDialog>();

                            break;
                        }
                    }
                    else if (section == "rs" || section == "remote-subsystem")
                    {
                        try
                        {
                            await App.SetLoadingAsync(true);

                            parser.TryGetValue("d", out var data);
                            parser.TryGetValue("t", out var timespan);

                            var result = App.RoamingService.DecodeActivityParameters(data);

                            // Get the current track object
                            BaseTrack currentTrack = null;
                            var       tracks       = new List <BaseTrack>();

                            switch (result.CurrentTrack.Service)
                            {
                            case ServiceType.Fanburst:
                                break;

                            case ServiceType.SoundCloud:
                            case ServiceType.SoundCloudV2:
                                currentTrack = (await SoundByteService.Current.GetAsync <SoundCloudTrack>(ServiceType.SoundCloud, $"/tracks/{result.CurrentTrack.TrackId}")).Response.ToBaseTrack();
                                break;

                            case ServiceType.YouTube:
                                currentTrack = (await SoundByteService.Current.GetAsync <YouTubeVideoHolder>(ServiceType.YouTube, "videos", new Dictionary <string, string>
                                {
                                    { "part", "snippet,contentDetails" },
                                    { "id", result.CurrentTrack.TrackId }
                                })).Response.Tracks.FirstOrDefault()?.ToBaseTrack();
                                break;

                            case ServiceType.ITunesPodcast:
                                // TODO: THIS
                                break;
                            }

                            //TODO: List has to be put back into wanted order.

                            var soundCloudIds = string.Join(',', result.Tracks.Where(x => x.Service == ServiceType.SoundCloud || x.Service == ServiceType.SoundCloudV2).Select(x => x.TrackId));
                            var fanburstIds   = string.Join(',', result.Tracks.Where(x => x.Service == ServiceType.Fanburst).Select(x => x.TrackId));
                            var youTubeIds    = string.Join(',', result.Tracks.Where(x => x.Service == ServiceType.YouTube).Select(x => x.TrackId));

                            // SoundCloud tracks
                            tracks.AddRange((await SoundByteService.Current.GetAsync <List <SoundCloudTrack> >(ServiceType.SoundCloud, $"/tracks?ids={soundCloudIds}")).Response.Select(x => x.ToBaseTrack()));

                            // YouTube Tracks
                            tracks.AddRange((await SoundByteService.Current.GetAsync <YouTubeVideoHolder>(ServiceType.YouTube, "videos", new Dictionary <string, string>
                            {
                                { "part", "snippet,contentDetails" },
                                { "id", youTubeIds }
                            })).Response.Tracks.Select(x => x.ToBaseTrack()));

                            var startPlayback = await PlaybackService.Instance.InitilizePlaylistAsync(result.Source, tracks);

                            if (startPlayback.Success)
                            {
                                TimeSpan?timeSpan = null;

                                if (!string.IsNullOrEmpty(timespan))
                                {
                                    timeSpan = TimeSpan.FromMilliseconds(double.Parse(timespan));
                                }

                                await PlaybackService.Instance.StartTrackAsync(currentTrack, timeSpan);
                            }
                            else
                            {
                                await NavigationService.Current.CallMessageDialogAsync(startPlayback.Message, "The remote protocol subsystem failed.");
                            }

                            await App.SetLoadingAsync(false);
                        }
                        catch (Exception e)
                        {
                            await App.SetLoadingAsync(false);

                            await NavigationService.Current.CallMessageDialogAsync(e.Message, "The remote protocol subsystem failed.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    await NavigationService.Current.CallMessageDialogAsync(
                        "The specified protocol is not correct. App will now launch as normal.\n\n" + ex.Message);
                }
                await App.SetLoadingAsync(false);
            }

            if (DeviceHelper.IsMobile)
            {
                RootFrame.Navigate(typeof(MobileView));
            }
            else
            {
                RootFrame.Navigate(typeof(ExploreView));
            }
        }