Ejemplo n.º 1
0
        private async void GetSoundCloudSessionStatus()
        {
            try
            {
                IsSoundCloudButtonEnabled = false;

                _soundCloudSessionStatus = await SoundCloudHelper.GetSessionStatusAsync();

                switch (_soundCloudSessionStatus)
                {
                case SoundCloudSessionStatus.Connected:
                    SoundCloudStatusText = AppResources.AccountConnectedStatusText;
                    break;

                case SoundCloudSessionStatus.NotConnected:
                    SoundCloudStatusText = AppResources.AccountDisconnectedStatusText;
                    break;

                case SoundCloudSessionStatus.Unknown:
                    SoundCloudStatusText = AppResources.AccountUnknownStatusText;
                    break;
                }
            }
            catch
            {
                SoundCloudStatusText = AppResources.AccountErrorStatusText;
            }
            finally
            {
                IsSoundCloudButtonEnabled = true;
            }
        }
Ejemplo n.º 2
0
        private async void SoundCloudLogin()
        {
            try
            {
                _soundCloudSessionStatus = await SoundCloudHelper.LoginAsync();

                switch (_soundCloudSessionStatus)
                {
                case SoundCloudSessionStatus.Connected:
                    SoundCloudStatusText = AppResources.AccountConnectedStatusText;
                    break;

                case SoundCloudSessionStatus.NotConnected:
                    SoundCloudStatusText = AppResources.AccountDisconnectedStatusText;
                    break;

                case SoundCloudSessionStatus.Unknown:
                    SoundCloudStatusText = AppResources.AccountUnknownStatusText;
                    break;
                }
            }
            catch
            {
                SkyDriveStatusText = AppResources.AccountErrorStatusText;
            }
        }
Ejemplo n.º 3
0
        public async override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            try
            {
                // Fill Genres and Kinds dictionaries
                GenresDictionary = await SoundCloudHelper.GetGenres();

                KindsDictionary = await SoundCloudHelper.GetKinds();

                foreach (var g in GenresDictionary)
                {
                    Genres.Add(g.Value);
                }
                foreach (var k in KindsDictionary)
                {
                    Kinds.Add(k.Value);
                }
                // Select first Genre and Kind
                SelectedGenre = Genres.FirstOrDefault();
                SelectedKind  = Kinds.FirstOrDefault();
                await base.OnNavigatedToAsync(parameter, mode, state);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex.Message);
                ShowErrorMessage("There was an error during fetching tracks from SoundCloud.");
            }
        }
Ejemplo n.º 4
0
        public async Task FetchIdTestAsync()
        {
            await SoundCloudHelper.ValidateClientIdAsync(_restClient)
            .ConfigureAwait(false);

            Assert.IsNotNull(SoundCloudHelper.ClientId);
        }
Ejemplo n.º 5
0
        public async void SearchTracks()
        {
            try
            {
                List <SoundCloudTrack> searchResult = await SoundCloudHelper.SearchTracks(TextToSearch, 50);

                Tracks.Clear();
                foreach (var result in searchResult)
                {
                    Tracks.Add(result);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex.Message);
                ShowErrorMessage("There was an error during searching tracks.");
            }
        }
Ejemplo n.º 6
0
        protected async void PlayLikes()
        {
            try
            {
                var userLikes = LikeService.GetLikes(App.User.id).ToList();
                if (userLikes.Count > 0)
                {
                    List <SoundCloudTrack> likedTracks   = new List <SoundCloudTrack>();
                    List <LikeToDisplay>   likesToDelete = new List <LikeToDisplay>();
                    foreach (var like in userLikes)
                    {
                        var track = await SoundCloudHelper.GetSoundCloudTrack(like.TrackID);

                        if (track != null)
                        {
                            likedTracks.Add(track);
                        }
                        else
                        {
                            likesToDelete.Add(like);
                        }
                    }
                    App.PlaylistManager.PlayTracks(likedTracks);
                    if (likesToDelete.Count > 0)
                    {
                        foreach (var likeToDelete in likesToDelete)
                        {
                            LikeService.DeleteLike(likeToDelete.id);
                        }
                        throw new SoundCloudTrackNotAvailableException($"Some of your tracks were deleted from likes, because they were no longer available on SoundCloud", likesToDelete.Select(l => l.TrackID).ToList());
                    }
                }
            }
            catch (SoundCloudTrackNotAvailableException ex)
            {
                Logger.LogWarning(this, ex.Message);
                ShowWarningMessage(ex.Message);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex.Message);
                ShowErrorMessage("There was an error during playing liked tracks.");
            }
        }
Ejemplo n.º 7
0
        private async Task <string> UploadToSoundCloudAsync()
        {
            _cts = new CancellationTokenSource();
            _cts.Token.Register(OnUploadCanceled);
            _scProgress = new Progress <SoundCloudUploadProgressChangedEventArgs>(OnSoundCloudUploadProgress);

            _cts.Token.ThrowIfCancellationRequested();

            var status = await SoundCloudHelper.GetSessionStatusAsync();

            if (status != SoundCloudSessionStatus.Connected)
            {
                throw new InvalidOperationException("Not connected.");
            }

            var link = await SoundCloudHelper.UploadFileAsync(_memo.Title, _memo.AudioFile, _memo.AudioFormat == "MP3"? "audio/x-mpeg" : "audio/x-wav", _cts.Token, _scProgress);

            return(link);
        }
Ejemplo n.º 8
0
        private async void SearchViewModel_SearchQueryChangedEvent()
        {
            try
            {
                if (textToSearch.Length > 2)
                {
                    SearchQuery.Clear();
                    List <SoundCloudTrack> searchResult = await SoundCloudHelper.SearchTracks(textToSearch, 50);

                    foreach (var result in searchResult)
                    {
                        SearchQuery.Add(result.title);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex.Message);
                ShowErrorMessage("There was an error during searching tracks.");
            }
        }
Ejemplo n.º 9
0
        public async Task GetTracks()
        {
            if (!String.IsNullOrEmpty(SelectedGenre) && !String.IsNullOrEmpty(SelectedKind))
            {
                try
                {
                    Tracks.Clear();
                    var tempTracks = await SoundCloudHelper.GetTracksByKindAndGenre(KindsDictionary.FirstOrDefault(x => x.Value == SelectedKind).Key, GenresDictionary.FirstOrDefault(x => x.Value == SelectedGenre).Key);

                    foreach (var track in tempTracks)
                    {
                        Tracks.Add(track);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError(this, ex.Message);
                    ShowErrorMessage("There was an error during fetching tracks from SoundCloud.");
                }
            }
        }
Ejemplo n.º 10
0
        private async void GetLikes()
        {
            try
            {
                var likesTrackIDs = LikeService.GetLikes(App.User.id).Select(l => l.TrackID).ToList();
                if (likesTrackIDs.Count > 0)
                {
                    foreach (var trackID in likesTrackIDs)
                    {
                        var track = await SoundCloudHelper.GetSoundCloudTrack(trackID);

                        Likes.Add(track);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex.Message);
                ShowErrorMessage("There was an error during getting licked tracks.");
            }
        }
Ejemplo n.º 11
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState)
        {
            try
            {
                HelloUserText = $"Hello, {App.User.username}";
                var recentlyPopularTracks =
                    (from th in TrackHistoryService.GetTracksHistory(App.User.id, 250)
                     group th by th.TrackID into g
                     select new { TrackID = g.Key, TrackCount = g.Count() }).Take(5);
                foreach (var track in recentlyPopularTracks)
                {
                    var t = await SoundCloudHelper.GetSoundCloudTrack(track.TrackID);

                    RecentlyPopularTracks.Add(t);
                }
                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex.Message);
                ShowErrorMessage("There was an error during fetching your recently popular tracks.");
            }
        }
Ejemplo n.º 12
0
 private void SoundCloudLogout()
 {
     SoundCloudHelper.Logout();
     _soundCloudSessionStatus = SoundCloudSessionStatus.NotConnected;
     SoundCloudStatusText     = AppResources.AccountDisconnectedStatusText;
 }