コード例 #1
0
        public IHttpActionResult Create(string code)
        {
            Session session = null;
            var     client  = new RestClient(Constants.Spotify.AccountsBaseApi);
            var     request = new RestRequest("token", Method.POST);

            request.AddHeader("content-type", "application/x-www-form-urlencoded");
            request.AddParameter("application/x-www-form-urlencoded", $"client_id={Constants.Spotify.ClientId}&client_secret={Constants.Spotify.ClientSecret}&grant_type={grantType}&code={code}&redirect_uri={Constants.Spotify.RedirectUri}", ParameterType.RequestBody);

            IRestResponse response = client.Execute(request);

            if (response.IsSuccessful)
            {
                SpotifyTokenResponse responseBody = JsonConvert.DeserializeObject <SpotifyTokenResponse>(response.Content);
                if (responseBody.scope != null && responseBody.access_token != null)
                {
                    SpotifyCredentials credentials = new SpotifyCredentials(responseBody.access_token, responseBody.refresh_token, new List <string>(responseBody.scope.Split(' ')));
                    IPlayer            player      = new SpotifyPlayer(credentials);
                    session = new Session(player);
                    sessions.Add(session);
                }
            }

            return(session != null ? (IHttpActionResult)Ok(session) : NotFound());
        }
コード例 #2
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void GetPlaylistsSucceedNotLoggedIn()
        {
            SpotifyPlayer          player            = CreateInitializedPlayer();
            Mock <ISpotifyWrapper> wrapper           = Mock.Get(player.Spotify);
            List <String>          expectedPlaylists = new List <string>
            {
                "Test Playlist",
                "Test Playlist 2",
                "Test Playlist 3",
            };

            wrapper.Setup(p => p.LogIn());
            wrapper.Setup(p => p.GetPlaylists()).Returns(expectedPlaylists);
            wrapper.Setup(p => p.LogOut());

            IEnumerable <String> playlists = player.GetPlaylists();

            wrapper.Verify(p => p.GetPlaylists(), Times.Exactly(1));
            wrapper.Verify(p => p.LogIn(), Times.Exactly(1));
            wrapper.Verify(p => p.LogOut(), Times.Exactly(1));
            Assert.AreEqual(expectedPlaylists.Count, playlists.Count());
            Assert.IsTrue(expectedPlaylists.Contains(playlists.ElementAt(0)));
            Assert.IsTrue(expectedPlaylists.Contains(playlists.ElementAt(1)));
            Assert.IsTrue(expectedPlaylists.Contains(playlists.ElementAt(2)));
            Assert.AreEqual(PlayerState.Stopped, player.State);
        }
コード例 #3
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void StopMusicFailNotPlaying()
        {
            SpotifyPlayer player = CreateInitializedPlayer();

            player.StopMusic();

            Assert.AreEqual(PlayerState.Stopped, player.State);
        }
コード例 #4
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void SkipToNextTrackFailNotPlaying()
        {
            SpotifyPlayer          player  = CreateLoggedInPlayer();
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);

            player.SkipToNextTrack();

            Assert.AreEqual(PlayerState.Stopped, player.State);
        }
コード例 #5
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        private void StopPlayer(SpotifyPlayer player)
        {
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);

            wrapper.Setup(p => p.LogOut());
            wrapper.Setup(p => p.StopMusic());

            player.StopMusic();
        }
コード例 #6
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void LogOutFailNotLoggedIn()
        {
            SpotifyPlayer          player  = CreateInitializedPlayer();
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);

            player.LogOut();

            Assert.AreEqual(PlayerState.Stopped, player.State);
        }
コード例 #7
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        private SpotifyPlayer CreateLoggedInPlayer()
        {
            SpotifyPlayer          player  = CreateInitializedPlayer();
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);

            wrapper.Setup(s => s.LogIn());
            player.LogIn();
            wrapper.ResetCalls();
            return(player);
        }
コード例 #8
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        private SpotifyPlayer CreateInitializedPlayer()
        {
            SpotifyPlayer          player  = new SpotifyPlayer();
            Mock <ISpotifyWrapper> spotify = new Mock <ISpotifyWrapper>(MockBehavior.Strict);

            player.Spotify = spotify.Object;

            player.Initialize(GetConfigurationManager());
            return(player);
        }
コード例 #9
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void ConstructorSetsCorrectValues()
        {
            SpotifyPlayer player = new SpotifyPlayer();

            Assert.AreEqual("Spotify", player.Name);
            Assert.AreEqual(2, player.Properties.Count());
            Assert.AreEqual(1, player.Properties.Count(p => p.Name.Equals("Username")));
            Assert.AreEqual(1, player.Properties.Count(p => p.Name.Equals("Password")));
            Assert.AreEqual(PlayerState.Stopped, player.State);
        }
コード例 #10
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void GetCurrentArtistNameFailNotPlaying()
        {
            SpotifyPlayer          player  = CreateLoggedInPlayer();
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);

            String artistName = player.GetCurrentArtistName();

            Assert.IsNull(artistName);
            Assert.AreEqual(PlayerState.Stopped, player.State);
        }
コード例 #11
0
ファイル: PlayerListener.cs プロジェクト: me-next/menext-app
            public void OnInitialized(SpotifyPlayer p0)
            {
                Log.Debug("PlayerInitObserver", "Player initialialised");
                var player = this.listener.Player;

                player.SetConnectivityStatus(this.listener.operationCallback,
                                             this.listener.GetNetworkConnectivity(this.listener.sms.mainActivity));
                player.AddNotificationCallback(this.listener);
                player.AddConnectionStateCallback(this.listener);
                this.listener.sms.SomethingChanged();
            }
コード例 #12
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void LogInSuccess()
        {
            SpotifyPlayer          player  = CreateInitializedPlayer();
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);

            wrapper.Setup(s => s.LogIn());

            player.LogIn();

            wrapper.Verify(s => s.LogIn(), Times.Exactly(1));
            Assert.AreEqual(PlayerState.Stopped, player.State);
        }
コード例 #13
0
        //##############################################################################################################################################################################################

        public MainWindow()
        {
            InitializeComponent();

            logBox1.AutoScrollToLastLogEntry = true;
            _logHandle = new Progress <LogEvent>(progressValue =>
            {
                logBox1.LogEvent(progressValue);
            });

            PlayerApp = new SpotifyPlayer(100, this);
        }
コード例 #14
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void DisposeInitialized()
        {
            SpotifyPlayer          player  = CreateInitializedPlayer();
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);

            wrapper.Setup(w => w.Dispose());

            player.Dispose();

            wrapper.Verify(w => w.Dispose(), Times.Exactly(1));
            Assert.IsNull(player.Spotify);
            Assert.AreEqual(PlayerState.Stopped, player.State);
        }
コード例 #15
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void SkipToNextTrackSucceed()
        {
            SpotifyPlayer          player  = CreatePlayingSpotifyPlayer();
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);

            wrapper.Setup(p => p.SkipToNextTrack());

            player.SkipToNextTrack();

            wrapper.Verify(p => p.SkipToNextTrack(), Times.Exactly(1));
            Assert.AreEqual(PlayerState.Playing, player.State);
            StopPlayer(player);
        }
コード例 #16
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void LogOutSucceedAlreadyPlaying()
        {
            SpotifyPlayer          player  = CreatePlayingSpotifyPlayer();
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);

            wrapper.Setup(p => p.LogOut());
            wrapper.Setup(p => p.StopMusic());

            player.LogOut();

            wrapper.Verify(p => p.StopMusic(), Times.Exactly(1));
            wrapper.Verify(p => p.LogOut(), Times.Exactly(1));
            Assert.AreEqual(PlayerState.Stopped, player.State);
        }
コード例 #17
0
 public SpotifyUserController
     (SpotifyUser userRepo,
     IMapper mapper,
     SpotifyPlayer playerRepo,
     ICookieManager cookiesManager,
     PublicUserViewModel userModel,
     UserProfileViewModel model)
 {
     _model          = model;
     _userModel      = userModel;
     _userRepo       = userRepo;
     _mapper         = mapper;
     _playerRepo     = playerRepo;
     _cookiesManager = cookiesManager;
 }
コード例 #18
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void TryStartPlaylistFailed()
        {
            SpotifyPlayer          player  = CreateInitializedPlayer();
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);

            wrapper.Setup(s => s.LogIn());
            player.LogIn();
            wrapper.ResetCalls();
            wrapper.Setup(s => s.TryStartPlaylist("test playlist", true)).Returns(false);

            player.TryStartPlaylist("test playlist", true);

            wrapper.Verify(s => s.TryStartPlaylist("test playlist", true), Times.Exactly(1));
            Assert.AreEqual(PlayerState.Stopped, player.State);
        }
コード例 #19
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void GetCurrentArtistNameSucceed()
        {
            SpotifyPlayer          player  = CreatePlayingSpotifyPlayer();
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);
            String expectedArtistName      = "Test Artist";

            wrapper.Setup(p => p.GetCurrentArtistName()).Returns(expectedArtistName);

            String artistName = player.GetCurrentArtistName();

            wrapper.Verify(p => p.GetCurrentArtistName(), Times.Exactly(1));
            Assert.AreEqual(expectedArtistName, artistName);
            Assert.AreEqual(PlayerState.Playing, player.State);
            StopPlayer(player);
        }
コード例 #20
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        private SpotifyPlayer CreatePlayingSpotifyPlayer()
        {
            SpotifyPlayer          player  = CreateLoggedInPlayer();
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);

            wrapper.Setup(s => s.TryStartPlaylist("test playlist", true)).Returns(true);
            player.TryStartPlaylist("test playlist", true);
            byte[] data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            IntPtr ptr  = Marshal.AllocHGlobal(data.Length);

            Marshal.Copy(data, 0, ptr, data.Length);
            wrapper.Raise(p => p.MusicDataAvailable += null, new MusicDeliveryEventArgs(ptr, data.Length, 44100, 2, 8));
            wrapper.ResetCalls();
            return(player);
        }
コード例 #21
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void DisposePlaying()
        {
            SpotifyPlayer          player  = CreatePlayingSpotifyPlayer();
            Mock <ISpotifyWrapper> wrapper = Mock.Get(player.Spotify);

            wrapper.Setup(w => w.Dispose());
            wrapper.Setup(w => w.LogOut());
            wrapper.Setup(w => w.StopMusic());

            player.Dispose();

            wrapper.Verify(w => w.StopMusic(), Times.Exactly(1));
            wrapper.Verify(w => w.LogOut(), Times.Exactly(1));
            wrapper.Verify(w => w.Dispose(), Times.Exactly(1));
            Assert.IsNull(player.Spotify);
            Assert.AreEqual(PlayerState.Stopped, player.State);
        }
コード例 #22
0
        public ConnectHandler AttachSpotifyConnect(
            ISpotifyDevice device,
            uint initialVolume,
            int volumeSteps)
        {
            WaitAuthLock();
            var player =
                new SpotifyPlayer(
                    this,
                    device,
                    initialVolume,
                    volumeSteps);

            var connectHandler
                = new ConnectHandler(this, player);

            return(connectHandler);
        }
コード例 #23
0
        private void InitPlayer(string accessToken)
        {
            if (_spotifyPlayer == null)
            {
                AccessToken = accessToken;

                var playerConfig = new Config(Forms.Context, accessToken, ApiConstants.SpotifyClientId);

                _spotifyPlayer = Spotify.GetPlayer(playerConfig, this, new InitializationObserverDelegate(p =>
                {
                    p.SetConnectivityStatus(_operationCallbackDelegate, GetNetworkConnectivity(Forms.Context));
                    p.AddNotificationCallback(this);
                    p.AddConnectionStateCallback(this);
                    p.Login(accessToken);
                }, throwable => LogStatus(throwable.ToString())));
            }
            else
            {
                _spotifyPlayer.Login(accessToken);
            }
        }
コード例 #24
0
ファイル: PlayerListener.cs プロジェクト: me-next/menext-app
 void OnAuthenticationComplete(AuthenticationResponse response)
 {
     // Once we have obtained an authorization token, we can proceed with creating a Player.
     Log.Debug("PlayerListener", "Gort auth token");
     if (this.Player == null)
     {
         var playerConfig = new Com.Spotify.Sdk.Android.Player.Config(
             this.sms.mainActivity.ApplicationContext, response.AccessToken, this.sms.ClientId
             );
         // Since the Player is a static singleton owned by the Spotify class, we pass "this" as
         // the second argument in order to refcount it properly. Note that the method
         // Spotify.destroyPlayer() also takes an Object argument, which must be the same as the
         // one passed in here. If you pass different instances to Spotify.getPlayer() and
         // Spotify.destroyPlayer(), that will definitely result in resource leaks.
         this.Player = Com.Spotify.Sdk.Android.Player.Spotify.GetPlayer(playerConfig, this, new PlayerInitObserver(this));
     }
     else
     {
         this.Player.Login(response.AccessToken);
     }
     this.sms.OnNewAccessToken(response.AccessToken);
     this.sms.SomethingChanged();
 }
コード例 #25
0
 public void OnInitialized(SpotifyPlayer player)
 {
     _onInitialized(player);
 }
コード例 #26
0
ファイル: SpotifyPlayerTests.cs プロジェクト: davidov541/SAMI
        public void InitializeSuccess()
        {
            SpotifyPlayer player = CreateInitializedPlayer();

            Assert.AreEqual(PlayerState.Stopped, player.State);
        }