PHP code example of dweb-x / volumio

1. Go to this page and download the library: Download dweb-x/volumio library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dweb-x / volumio example snippets


return [
    // The base URL of your Volumio instance
    'base_url' => env('VOLUMIO_API_URL', 'http://localhost:3000'),

    // API request timeout in seconds
    'timeout' => env('VOLUMIO_API_TIMEOUT', 10),

    // Connection retry attempts
    'retries' => env('VOLUMIO_API_RETRIES', 3),

    // Default request options for Guzzle
    'http_options' => [
        'headers' => [
            'Accept' => 'application/json',
            'Content-Type' => 'application/json',
        ],
    ],
];

'base_url' => env('VOLUMIO_API_URL', 'http://localhost:3000'),

'timeout' => env('VOLUMIO_API_TIMEOUT', 10),

'retries' => env('VOLUMIO_API_RETRIES', 3),

'http_options' => [
    'headers' => [
        'Accept' => 'application/json',
        'Content-Type' => 'application/json',
    ],
],

use Dwebx\Volumio\Facades\Volumio;

// Get the current player state
$state = Volumio::getState();

// Get the current queue
$queue = Volumio::getQueue();

// Playback controls
Volumio::toggle(); // Play/pause
Volumio::pause(); // Pause playback
Volumio::next(); // Next track
Volumio::previous(); // Previous track
Volumio::stop(); // Stop playback

// Volume controls
Volumio::setVolume(75); // Set volume (0-100)
Volumio::volumeUp(); // Increase volume
Volumio::volumeDown(); // Decrease volume
Volumio::mute(); // Mute volume
Volumio::unmute(); // Unmute volume

// You can also use the Volume enum
use Dwebx\Volumio\Enums\Volume;
Volumio::setVolume(Volume::PLUS); // Increase volume
Volumio::setVolume(Volume::MINUS); // Decrease volume
Volumio::setVolume(Volume::MUTE); // Mute
Volumio::setVolume(Volume::UNMUTE); // Unmute

// Queue management
Volumio::play(2); // Play a specific item from the queue (0-based index)
Volumio::clearQueue(); // Clear the queue

// Playback modes
Volumio::repeat(); // Toggle repeat mode
Volumio::repeat(true); // Enable repeat mode
Volumio::repeat(false); // Disable repeat mode
Volumio::random(); // Toggle random mode
Volumio::random(true); // Enable random mode
Volumio::random(false); // Disable random mode

// Playlist management
$playlists = Volumio::listPlaylists(); // Get list of playlists
Volumio::playPlaylist('Rock'); // Play a specific playlist

// Browsing and searching
$root = Volumio::browse(); // Browse root directory
$musicLibrary = Volumio::browse('music-library'); // Browse music library
$limitedResults = Volumio::browse('music-library', 10, 5); // Limit to 10 results, starting from the 5th
$searchResults = Volumio::search('Pink Floyd'); // Search for content

// Advanced queue management
$items = [
    [
        'uri' => 'music-library/song.flac',
        'service' => 'mpd',
        'title' => 'Song Title',
        'artist' => 'Artist Name',
        'album' => 'Album Name',
        'type' => 'song',
    ],
];
Volumio::addToQueue($items); // Add items to queue

$data = [
    'item' => [
        'uri' => 'music-library/song.flac',
        'service' => 'mpd',
        'title' => 'Song Title',
    ],
    'list' => $items,
    'index' => 0,
];
Volumio::replaceAndPlay($data); // Replace queue and play

// System information
$stats = Volumio::getCollectionStats(); // Get collection statistics
$zones = Volumio::getZones(); // Get information about Volumio zones
$pong = Volumio::ping(); // Ping the Volumio API
$version = Volumio::getSystemVersion(); // Get system version
$info = Volumio::getSystemInfo(); // Get system information

// Push notifications
$urls = Volumio::getPushNotificationUrls(); // Get list of push notification URLs
Volumio::addPushNotificationUrl('http://example.com/callback'); // Add a push notification URL
Volumio::removePushNotificationUrl('http://example.com/callback'); // Remove a push notification URL

use Dwebx\Volumio\Volumio;

class MyController
{
    public function index(Volumio $volumio)
    {
        $state = $volumio->getState();

        return view('my-view', [
            'playerState' => $state,
        ]);
    }
}

// Example response from getState()
[
    'status' => 'play',
    'title' => 'Song Title',
    'artist' => 'Artist Name',
    'album' => 'Album Name',
    'volume' => 50,
    // ... other state information
]

use Dwebx\Volumio\Facades\Volumio;

try {
    $state = Volumio::getState();
    // Process the state
} catch (\Exception $e) {
    // Handle the error
    Log::error('Volumio API error: ' . $e->getMessage());
}
bash
php artisan vendor:publish --tag="volumio-config"