Skip to content
← Public packages

@kentcdodds/spotify

Spotify playback, playlist, search, library, and device helpers.

src/exports/playback-state.ts

21 lines · 871 B · TypeScript
import { getPlaybackState, normalizePlaybackState } from '../lib/spotify-api.ts'
import type { PlaybackStateParams } from '../lib/export-types.ts'

/**
 * Read the current Spotify playback state for an account.
 * All params accept an optional `account` ('personal' | 'family', default 'personal').
 * @returns Normalized playback object, or { ok: true, nothing_playing: true } when idle.
 * @example
 * import playbackState from 'kody:@kentcdodds/spotify/playback-state'
const state = await playbackState({ account: 'personal' })
// => { isPlaying: true, item: { name: '...' }, device: { ... } }
 */
async function playbackState(params: PlaybackStateParams = {}) {
	const result = await getPlaybackState(params)
	if (result.nothingPlaying) {
		return { ok: true, nothing_playing: true }
	}
	return normalizePlaybackState(result.playback)
}

export default playbackState