Spotify Playback Control Service

This module provides comprehensive functionality for controlling and monitoring Spotify playback, enabling the application to interact with the user's active playback sessions across devices.

Features:

  • Current playback state monitoring
  • Track information retrieval
  • Recently played tracks history
  • Playback control actions (play, pause, skip)
  • Active device management
  • Comprehensive error handling for all playback operations
  • Automatic token validation before API calls
  • Intelligent handling of common playback scenarios

The playback control module serves as the foundation for the application's core functionality of monitoring and analyzing user listening behavior, particularly focusing on skip detection and playback patterns.

Usage:

import {
getCurrentPlayback,
getRecentlyPlayedTracks,
play,
pause,
skipToNext
} from '@/services/spotify/playback';

// Get current playback
const state = await getCurrentPlayback();
if (state?.is_playing) {
// User is currently listening to something
console.log(`Now playing: ${state.item.name}`);
}

// Control playback
await skipToNext(); // Skip to next track
await pause(); // Pause playback

Functions

getCurrentPlayback
getTrack
getRecentlyPlayedTracks
pause
play
skipToPrevious
skipToNext