Exemplo n.º 1
0
        private void ShareSoundByte(object sender, RoutedEventArgs e)
        {
            // Create a data package
            var dataPackage = new DataPackage {
                RequestedOperation = DataPackageOperation.Copy
            };

            // Set the link to the track on soundcloud
            dataPackage.SetText($"soundbyte://track?d={ProtocolHelper.EncodeTrackProtocolItem(new ProtocolHelper.TrackProtocolItem(null, new BaseSoundByteItem(Track)), false)}");
            // Set the clipboard content
            Clipboard.SetContent(dataPackage);
            // Hide the popup
            Hide();
            // Track Event
            SimpleIoc.Default.GetInstance <ITelemetryService>().TrackEvent("Share Menu - Copy SoundByte Link");
        }
Exemplo n.º 2
0
        public async void RemoteSystemItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                LoadingPane.Visibility = Windows.UI.Xaml.Visibility.Visible;
                var system = (RemoteSystem)e.ClickedItem;

                if (SimpleIoc.Default.GetInstance <IPlaybackService>().GetCurrentTrack() != null)
                {
                    var track    = new BaseSoundByteItem(SimpleIoc.Default.GetInstance <IPlaybackService>().GetCurrentTrack());
                    var playlist = SimpleIoc.Default.GetInstance <IPlaybackService>().GetMediaPlaybackList().Items.Select(x => new BaseSoundByteItem(x.Source.AsBaseTrack()));
                    var token    = SimpleIoc.Default.GetInstance <IPlaybackService>().GetPlaylistToken();
                    var source   = SimpleIoc.Default.GetInstance <IPlaybackService>().GetPlaylistSource();

                    var status = await RemoteLauncher.LaunchUriAsync(new RemoteSystemConnectionRequest(system),
                                                                     new Uri(ProtocolHelper.EncodeTrackProtocolItem(new ProtocolHelper.TrackProtocolItem(source, track, playlist, token, SimpleIoc.Default.GetInstance <IPlaybackService>().GetTrackDuration()), true)));

                    if (status == RemoteLaunchUriStatus.Success)
                    {
                        Hide();
                        LoadingPane.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    }
                    else
                    {
                        Hide();
                        LoadingPane.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                        await NavigationService.Current.CallMessageDialogAsync("Failed with status: " + status, "Remote System Error");
                    }
                }
                else
                {
                    Hide();
                    LoadingPane.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    await NavigationService.Current.CallMessageDialogAsync("A track must be playing", "Remote System Error");
                }
            }
            finally
            {
                LoadingPane.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
        }
Exemplo n.º 3
0
        private async Task AppSuspendingAsync(object sender, SuspendingEventArgs e)
        {
            var def = e.SuspendingOperation.GetDeferral();

            try
            {
                // Clear live tile
                var updater = TileUpdateManager.CreateTileUpdaterForApplication();
                updater.Clear();

                var playbackService = SimpleIoc.Default.GetInstance <IPlaybackService>();
                if (playbackService != null)
                {
                    // Save current position
                    var currentPosition = playbackService.GetMediaPlayer()?.PlaybackSession?.Position;
                    await RoamingService.StopActivityAsync(currentPosition);

                    // Update the resume files
                    var roamingFolder = ApplicationData.Current.RoamingFolder;

                    var track    = new BaseSoundByteItem(playbackService.GetCurrentTrack());
                    var playlist = playbackService.GetMediaPlaybackList().Items.Select(x => new BaseSoundByteItem(x.Source.AsBaseTrack()));
                    var token    = playbackService.GetPlaylistToken();
                    var source   = playbackService.GetPlaylistSource();

                    var playbackFile = await roamingFolder.CreateFileAsync("currentPlayback.txt", CreationCollisionOption.OpenIfExists);

                    await FileIO.WriteTextAsync(playbackFile,
                                                ProtocolHelper.EncodeTrackProtocolItem(new ProtocolHelper.TrackProtocolItem(source, track, playlist, token, SimpleIoc.Default.GetInstance <IPlaybackService>().GetTrackPosition(), SimpleIoc.Default.GetInstance <IPlaybackService>().IsPlaylistShuffled()), false) + "\n" + SettingsService.Instance.SessionId);
                }
            }
            catch (Exception ex)
            {
                SimpleIoc.Default.GetInstance <ITelemetryService>().TrackException(ex);
            }
            finally
            {
                def.Complete();
            }
        }
Exemplo n.º 4
0
        public async Task <UserActivity> UpdateActivityAsync(ISource source, BaseTrack track, IEnumerable <BaseSoundByteItem> playlist, string token, TimeSpan?timeSpan, bool isShuffled)
        {
            // Don't enable if windows timeline support is disabled
            if (!SettingsService.Instance.WindowsTimelineEnabled)
            {
                return(null);
            }

            // We do not support these items
            if (track.ServiceType == ServiceTypes.ITunesPodcast ||
                track.ServiceType == ServiceTypes.Local ||
                track.ServiceType == ServiceTypes.Unknown)
            {
                return(null);
            }

            var activity = await _channel.GetOrCreateUserActivityAsync("playback-" + SettingsService.Instance.SessionId);

            activity.FallbackUri = new Uri("https://soundbytemedia.com/pages/remote-subsystem");

            var continueText = @"Continue listening to " + track.Title.Replace('"', ' ') + " and " + playlist.Count() + " other songs.";

            activity.VisualElements.DisplayText = track.Title.Replace('"', ' ');
            activity.VisualElements.Description = continueText;

            var json = @"{""$schema"":""http://adaptivecards.io/schemas/adaptive-card.json"",""type"":""AdaptiveCard"",""backgroundImage"":""" + track.ArtworkUrl + @""",""version"": ""1.0"",""body"":[{""type"":""Container"",""items"":[{""type"":""TextBlock"",""text"":""" + track.Title.Replace('"', ' ') + @""",""weight"":""bolder"",""size"":""large"",""wrap"":true,""maxLines"":3},{""type"":""TextBlock"",""text"":""" + continueText + @""",""size"":""default"",""wrap"":true,""maxLines"":3}]}]}";

            activity.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(json);

            // Set the activation url using shorthand protocol
            var protoUri = ProtocolHelper.EncodeTrackProtocolItem(new ProtocolHelper.TrackProtocolItem(source, new BaseSoundByteItem(track), playlist, token, timeSpan, isShuffled), true) + "&session=" + SettingsService.Instance.SessionId;

            activity.ActivationUri = new Uri(protoUri);

            await activity.SaveAsync();

            return(activity);
        }
Exemplo n.º 5
0
        private async Task MediaPlaybackListOnCurrentItemChangedAsync(MediaPlaybackList sender, CurrentMediaPlaybackItemChangedEventArgs args)
        {
            var track = args.NewItem?.Source.AsBaseTrack();

            // If there is no new item, don't do anything
            if (track == null)
            {
                return;
            }

            // Invoke the track change method
            OnTrackChange?.Invoke(track);

            // Update the live tile
            UpdateTile(track);

            await Task.Run(async() =>
            {
                string currentUsageLimit;
                var memoryUsage = MemoryManager.AppMemoryUsage / 1024 / 1024;

                if (memoryUsage > 512)
                {
                    currentUsageLimit = "More than 512MB";
                }
                else if (memoryUsage > 256)
                {
                    currentUsageLimit = "More than 256MB";
                }
                else if (memoryUsage > 128)
                {
                    currentUsageLimit = "More than 128MB";
                }
                else
                {
                    currentUsageLimit = "Less than 128MB";
                }

                _telemetryService.TrackEvent("Current Song Change", new Dictionary <string, string>
                {
                    { "Current Usage", currentUsageLimit },
                    { "Free", SystemInformation.AvailableMemory.ToString(CultureInfo.InvariantCulture) },
                    { "Track Type", track.ServiceType.ToString() ?? "Null" },
                    { "Device", SystemInformation.DeviceFamily },
                    { "Current Version / First Version", SystemInformation.FirstVersionInstalled.ToFormattedString() + "/" + SystemInformation.ApplicationVersion.ToFormattedString() },
                });

                try
                {
                    // Only perform logic if soundbyte account is connected
                    // and the track type is not a local track
                    if (SoundByteService.Current.IsSoundByteAccountConnected &&
                        track.ServiceType != ServiceTypes.Local)
                    {
                        await SoundByteService.Current.PostItemAsync(ServiceTypes.SoundByte, "history", track);
                    }
                }
                catch (Exception ex)
                {
                    _telemetryService.TrackException(ex);
                }
            });

            try
            {
                // The correct playlist
                var tempPlaylist = new List <BaseSoundByteItem>();
                tempPlaylist.AddRange(_mediaPlaybackList.ShuffleEnabled
                    ? _mediaPlaybackList.ShuffledItems.Select(x => new BaseSoundByteItem(x.Source.AsBaseTrack())).ToList()
                    : _mediaPlaybackList.Items.Select(x => new BaseSoundByteItem(x.Source.AsBaseTrack())).ToList());

                // Update roaming activity
                await App.RoamingService.UpdateActivityAsync(_playlistSource, track, tempPlaylist, _playlistToken, null, IsPlaylistShuffled());

                // Update the resume files
                var roamingFolder = SettingsService.Instance.SyncLastPlayed
                    ? ApplicationData.Current.RoamingFolder
                    : ApplicationData.Current.LocalFolder;

                // Save in file
                var playbackFile = await roamingFolder.CreateFileAsync("currentPlayback.txt", CreationCollisionOption.OpenIfExists);

                await FileIO.WriteTextAsync(playbackFile, ProtocolHelper.EncodeTrackProtocolItem(new ProtocolHelper.TrackProtocolItem(_playlistSource, new BaseSoundByteItem(track), tempPlaylist, _playlistToken, null, _mediaPlaybackList.ShuffleEnabled), false));
            }
            catch
            {
                // Ignore
            }

            // Find the index of this item and see if we are near the end
            var currentIndex = _mediaPlaybackList.ShuffleEnabled
                ? _mediaPlaybackList.ShuffledItems.ToList().IndexOf(args.NewItem)
                : _mediaPlaybackList.Items.IndexOf(args.NewItem);

            var maxIndex = _mediaPlaybackList.ShuffleEnabled
                ? _mediaPlaybackList.ShuffledItems.Count - 1
                : _mediaPlaybackList.Items.Count - 1;

            // When we are three items from the end, load more items
            if (currentIndex >= maxIndex - 3)
            {
                try
                {
                    var newItems = await _playlistSource.GetItemsAsync(50, _playlistToken);

                    _playlistToken = newItems.Token;

                    if (newItems.IsSuccess)
                    {
                        // Loop through all the tracks and add them to the playlist
                        foreach (var newTrack in newItems.Items)
                        {
                            if (newTrack.Type != ItemType.Track)
                            {
                                continue;
                            }

                            try
                            {
                                BuildMediaItem(newTrack.Track);
                            }
                            catch (Exception e)
                            {
                                _telemetryService.TrackEvent("Playback Item Addition Failed", new Dictionary <string, string>
                                {
                                    { "TrackID", newTrack.Track.TrackId },
                                    { "TrackService", newTrack.Track.ServiceType.ToString() },
                                    { "ErrorMessage", e.Message }
                                });
                            }
                        }
                    }
                }
                catch
                {
                    _playlistToken = "eol";
                }
            }
        }