SpotifyApiSpotify LogoJS

Player src/managers/Player.ts#L29

A manager to perform actions which belongs to the spotify player web api.


Properties:

client

Methods:

addItem getCurrentPlayback getCurrentlyPlaying getDevices getRecentlyPlayed pause play previous seek setRepeatState setShuffleState setVolume skip transferPlayback

constructor(client) src/managers/Player.ts#L29

No documentation found.

NameTypeDescription
clientClientThe spotify api client.

.client src/managers/Player.ts#L19

Type:

Client

The spotify client.

.addItem(uri, deviceID) src/managers/Player.ts#L248

Add an item to the current user's queue. This method requires a spotify premium account.

await player.addItem('uri');

Returns:

Promise<boolean>

Parameters:

NameTypeDescription
uristringThe uri of the track or the episode to add to the queue.
deviceIDstringThe id of the device this command is targeting. If not supplied, the user’s currently active device is the target.
OPTIONAL

.getCurrentPlayback(additionalTypes) src/managers/Player.ts#L39

Get the current playback of the current user's player.

const currentPlayback = await player.getCurrentPlayback();

Returns:

Promise<"null" | CurrentPlayback>

Parameters:

NameTypeDescription
additionalTypes"track" | "episode"A comma-separated list of item types that your client supports besides the default track type. Valid types are: track and episode.
OPTIONAL

.getCurrentlyPlaying(additionalTypes) src/managers/Player.ts#L50

Get the current playing content of the current user's player.

const currentPlayback = await player.getCurrentlyPlaying();

Returns:

Promise<"null" | CurrentPlayback>

Parameters:

NameTypeDescription
additionalTypes"track" | "episode"A comma-separated list of item types that your client supports besides the default track type. Valid types are: track and episode.
OPTIONAL

.getDevices() src/managers/Player.ts#L69

Get the active devices which are logged into the current user's spotify account.

const devices = await player.getDevices();

Returns:

Promise<CamelCaseObjectKeys<Device>[]>

Parameters:

NameTypeDescription

.getRecentlyPlayed(options) src/managers/Player.ts#L61

Get the recently played data from the current user's player.

const recentlyPlayed = await player.getRecentlyPlayed();

Returns:

Promise<RecentlyPlayed>

Parameters:

NameTypeDescription
optionsPartial<Cursor> & { limit?: number, }The before, after and limit query paramaeters.

.pause(deviceID) src/managers/Player.ts#L133

Pause the current user's playback. This method requires a spotify premium account.

await player.pause();

Returns:

Promise<boolean>

Parameters:

NameTypeDescription
deviceIDstringThe id of the device this command is targeting. If not supplied, the user’s currently active device is the target.
OPTIONAL

.play(options) src/managers/Player.ts#L104

Play or resume the current user's playback. This method requires a spotify premium account. This methods uses the [/me/player/play] endpoint which does not has complete documentation.

await player.play();

Returns:

Promise<boolean>

Parameters:

NameTypeDescription
options{ contextURI?: string, deviceID?: string, offset?: number, position?: number, uris?: string[], }The deviceID, contextURI, uris, offset and position parameter.

.previous(deviceID) src/managers/Player.ts#L161

Skip to the previous track in the current user's playback. This method requires a spotify premium account.

await player.previous();

Returns:

Promise<boolean>

Parameters:

NameTypeDescription
deviceIDstringThe id of the device this command is targeting. If not supplied, the user’s currently active device is the target.
OPTIONAL

.seek(position, deviceID) src/managers/Player.ts#L176

Seek to a paticular position in the current user's player. This method requires a spotify premium account.

await player.seek(10000);

Returns:

Promise<boolean>

Parameters:

NameTypeDescription
positionnumberThe position in milliseconds to seek to. 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.
deviceIDstringThe id of the device this command is targeting. If not supplied, the user’s currently active device is the target.
OPTIONAL

.setRepeatState(state, deviceID) src/managers/Player.ts#L194

Set the repeat mode for the user’s playback. This method requires a spotify premium account.

await player.setRepeatState('off');

Returns:

Promise<boolean>

Parameters:

NameTypeDescription
state"track" | "off" | "context"State should be track, context or off. **track** will repeat the current track. **context** will repeat the current context. **off** will turn repeat off.
deviceIDstringThe id of the device this command is targeting. If not supplied, the user’s currently active device is the target.
OPTIONAL

.setShuffleState(state, deviceID) src/managers/Player.ts#L212

Toggle shuffle state for the current user's playback. This method requires a spotify premium account.

await player.setShuffleState();

Returns:

Promise<boolean>

Parameters:

NameTypeDescription
statebooleanThe shuffle state to set.
deviceIDstringThe id of the device this command is targeting. If not supplied, the user’s currently active device is the target.
OPTIONAL

.setVolume(volume, deviceID) src/managers/Player.ts#L230

Set volume for the current user's player. This method requires a spotify premium account.

await player.setVolume(80);

Returns:

Promise<boolean>

Parameters:

NameTypeDescription
volumenumberThe volume to set. Must be a value from 0 to 100 inclusive.
deviceIDstringThe id of the device this command is targeting. If not supplied, the user’s currently active device is the target.
OPTIONAL

.skip(deviceID) src/managers/Player.ts#L147

Skip to the next track in the current user's playback. This method requires a spotify premium account.

await player.skip();

Returns:

Promise<boolean>

Parameters:

NameTypeDescription
deviceIDstringThe id of the device this command is targeting. If not supplied, the user’s currently active device is the target.
OPTIONAL

.transferPlayback(deviceID, play) src/managers/Player.ts#L81

Transfer the playback to an another device. This method requires a spotify premium account.

await player.transferPlayback('deviceID');

Returns:

Promise<boolean>

Parameters:

NameTypeDescription
deviceIDstringThe device id to be transferred.
playbooleanThe playback state to set by default it is false.