Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SpotifyPlayer

Spotify web player.

Hierarchy

  • SpotifyPlayer

Index

Constructors

constructor

  • new SpotifyPlayer(name: string, volume?: number): SpotifyPlayer
  • Create a new SpotifyPlayer instance.

    Parameters

    • name: string

      Player name.

    • volume: number = 1.0

      Volume level. (default = 1.0)

    Returns SpotifyPlayer

Properties

Readonly scopes

scopes: string[] = ...

Required scopes for a token.

Accessors

error

  • get error(): string
  • Error message. (empty if no error occurred)

    Returns string

errorType

  • get errorType(): "" | "initialization_error" | "authentication_error" | "account_error" | "playback_error"
  • Error type. (empty if no error occurred)

    Returns "" | "initialization_error" | "authentication_error" | "account_error" | "playback_error"

playing

  • get playing(): boolean
  • Indicates if a media is playing.

    Returns boolean

position

  • get position(): number

ready

  • get ready(): boolean
  • Indicates if the player has been initialized and is ready for playing.

    Returns boolean

track

Methods

connect

  • connect(token: string): Promise<unknown>
  • Connect to Spotify.

    Parameters

    • token: string

      Spotify token.

    Returns Promise<unknown>

    true if successful, false otherwise.

getDevices

getPlaybackState

getTracksStatus

  • getTracksStatus(tracks: string | string[]): Promise<boolean[]>
  • Check if a track or a list of tracks is saved in the user's library.

    Parameters

    • tracks: string | string[]

    Returns Promise<boolean[]>

next

  • next(): Promise<void>
  • Skip to the next track.

    Returns Promise<void>

pause

  • pause(): Promise<void>

play

  • play(items?: string | string[], offset?: number): Promise<void>
  • Begin playback.

    Parameters

    • Optional items: string | string[]
    • offset: number = 0

    Returns Promise<void>

previous

  • previous(): Promise<void>
  • Skip to the previous track.

    Returns Promise<void>

seek

  • seek(position: number): Promise<void>
  • Seek to position.

    Parameters

    • position: number

    Returns Promise<void>

setDevice

  • setDevice(deviceId: string, shouldPlay?: boolean): Promise<Response>

setVolume

  • setVolume(volume: number): Promise<void>
  • Set the current volume level

    Parameters

    • volume: number

      Volume percentage from 0 to 100.

    Returns Promise<void>

Protected waitForConnection

  • waitForConnection(): Promise<unknown>
  • Wait for the player to connect and emit the 'ready' signal.

    Returns Promise<unknown>

    Promise that resolves to a boolean indicating if the connection was successful.

Protected waitForReady

  • waitForReady(): Promise<void>
  • Appends a script to spotify-player.js to the DOM.

    Returns Promise<void>

    Promise that resolves when the web player script has been loaded.

Generated using TypeDoc