public void PlaylistUri_NumericUsername_ExtractsValidUri()
        {
            // arrange
            const string fullUri = "spotify:user:1298341199:playlist:6RTNx0BJWjbmJuEfvMau3r";

            // act
            string uri = SpotifyUriHelper.PlaylistUri(fullUri);

            // assert
            Assert.AreEqual(fullUri, uri);
        }
        public void PlaylistUri_NumericUserIdInUri_ReturnsPlaylistUri()
        {
            // arrange
            const string uri = "spotify:user:122740800:playlist:6CI5ScAEKJdHMmQsfjHOmY";

            // act
            string result = SpotifyUriHelper.PlaylistUri(uri);

            // assert
            Assert.AreSame(uri, result);
        }
        public void PlaylistUri_DashInUserUri_ReturnsPlaylistUri()
        {
            // arrange
            const string uri = "spotify:user:trojan-records:playlist:0HHuexBIs4gdPZ2WeNGDt3";

            // act
            string result = SpotifyUriHelper.PlaylistUri(uri);

            // assert
            Assert.AreSame(uri, result);
        }
        public void PlaylistUri_UnderscoreInUri_ReturnsPlaylistUri()
        {
            // arrange
            const string uri = "spotify:user:catstevens_islanduk:playlist:4DgyX0TYmDJvjKlAVtkRxo";
            //spotify:user:122740800:playlist:6CI5ScAEKJdHMmQsfjHOmY
            // act
            string result = SpotifyUriHelper.PlaylistUri(uri);

            // assert
            Assert.AreSame(uri, result);
        }
        public void PlaylistUri_ValidPlaylistUri_ReturnsPlaylistUri()
        {
            // arrange
            const string uri = "spotify:playlist:0TnOYISbd1XYRBk9myaseg";

            // act
            string result = SpotifyUriHelper.PlaylistUri(uri);

            // assert
            Assert.AreSame(uri, result);
        }
        public void PlaylistUri_PlaylistUriMoreThan3Parts_ExtractsValidUri()
        {
            // arrange
            const string playlistUri = "spotify:playlist:0TnOYISbd1XYRBk9myaseg";
            string       fullUri     = $"spotify:user:{playlistUri}";

            // act
            string uri = SpotifyUriHelper.PlaylistUri(fullUri);

            // assert
            Assert.AreEqual(playlistUri, uri);
        }
Esempio n. 7
0
        /// <summary>
        /// BETA. Play a Playlist on the user’s active device.
        /// </summary>
        /// <param name="playlistId">Spotify Playlist Id to play</param>
        /// <param name="accessToken">Optional. A valid access token from the Spotify Accounts service.
        /// The access token must have been issued on behalf of a user. The access token must have the
        /// `user-modify-playback-state` scope authorized in order to control playback. <seealso cref="UserAccountsService"/>
        /// </param>
        /// <param name="deviceId">Optional. The id of the device this command is targeting. If not supplied, the user’s
        /// currently active device is the target.</param>
        /// <param name="positionMs">Optional. Indicates from what position to start playback. Must be a positive number.
        /// Passing in a position that is greater than the length of the track will cause the player to start playing the
        /// next song.</param>
        /// <remarks>
        /// https://developer.spotify.com/documentation/web-api/reference/player/start-a-users-playback/
        /// </remarks>
        public async Task PlayPlaylist(
            string playlistId,
            string accessToken = null,
            string deviceId    = null,
            long positionMs    = 0)
        {
            if (string.IsNullOrEmpty(playlistId))
            {
                throw new ArgumentNullException(nameof(playlistId));
            }
            dynamic data = JObject.FromObject(new { context_uri = SpotifyUriHelper.PlaylistUri(playlistId) });

            await Play(data, accessToken, deviceId, positionMs);
        }
Esempio n. 8
0
        /// <summary>
        /// BETA. Play a Playlist on the user’s active device.
        /// </summary>
        /// <param name="playlistId">Spotify Playlist Id to play</param>
        /// <param name="offsetPosition">From where in the Playlist playback should start, i.e. Track number</param>
        /// <param name="accessToken">Optional. A valid access token from the Spotify Accounts service.
        /// The access token must have been issued on behalf of a user. The access token must have the
        /// `user-modify-playback-state` scope authorized in order to control playback. <seealso cref="UserAccountsService"/>
        /// </param>
        /// <param name="deviceId">Optional. The id of the device this command is targeting. If not supplied, the user’s
        /// currently active device is the target.</param>
        /// <param name="positionMs">Optional. Indicates from what position to start playback. Must be a positive number.
        /// Passing in a position that is greater than the length of the track will cause the player to start playing the
        /// next song.</param>
        /// <remarks>
        /// https://developer.spotify.com/documentation/web-api/reference/player/start-a-users-playback/
        /// </remarks>
        public async Task PlayPlaylistOffset(
            string playlistId,
            int offsetPosition,
            string accessToken = null,
            string deviceId    = null,
            long positionMs    = 0)
        {
            dynamic data = JObject.FromObject(new { context_uri = SpotifyUriHelper.PlaylistUri(playlistId) });

            if (offsetPosition > 0)
            {
                data.offset = JObject.FromObject(new { position = offsetPosition });
            }
            await Play(data, accessToken, deviceId, positionMs);
        }