Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Spotify Web Api Php Laravel Package

jwilsson/spotify-web-api-php

View on GitHub
Deep Wiki
Context7

Controlling User Playback

Using Spotify Connect, it's possible to control the playback of the currently authenticated user.

Getting user devices

The SpotifyWebAPI::getMyDevices() method can be used to list out a user's devices.

// Get the Devices
$api->getMyDevices();

It is worth noting that if all devices have is_active set to false then using SpotifyWebApi::play() will fail.

Start and stop playback

// With Device ID
$api->play($deviceId, [
    'uris' => ['TRACK_URI'],
]);

// Without Device ID
$api->play(false, [
    'uris' => ['TRACK_URI'],
]);

$api->pause();

Playing the next or previous track

$api->previous();

$api->next();

Adding a track to the queue

$api->queue('TRACK_ID');

Get info about the queue

$api->getMyQueue();

Get the currently playing track

$api->getMyCurrentTrack();

Get info about the current playback

$api->getMyCurrentPlaybackInfo();

Move to a specific position in a track

$api->seek([
    'position_ms' => 60000 + 37000, // Move to the 1.37 minute mark
]);

Set repeat and shuffle mode

$api->repeat([
    'state' => 'track',
]);

$api->shuffle([
    'state' => false,
]);

Control the volume

$api->changeVolume([
    'volume_percent' => 78,
]);

Retrying API calls

Sometimes, a API call might return a 202 Accepted response code. When this occurs, you should retry the request after a few seconds. For example:

try {
    $wasPaused = $api->pause():

    if (!$wasPaused) {
        $lastResponse = $api->getLastResponse();

        if ($lastResponse['status'] == 202) {
            // Perform some logic to retry the request after a few seconds
        }
    }
} catch (Exception $e) {
    $reason = $e->getReason();

    // Check the reason for the failure and handle the error
}

Read more about working with Spotify Connect in the Spotify API docs.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle