PHP code example of radioapi / php

1. Go to this page and download the library: Download radioapi/php 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/ */

    

radioapi / php example snippets


use RadioApi\Client;

$radio = new Client(
    baseUrl: 'https://radioapi.example.com',
    apiKey: 'radio_live_YOUR_API_KEY',
);

$radio = Client::make('https://radioapi.example.com', 'radio_live_YOUR_API_KEY');

$radio = Client::make('https://radioapi.example.com', 'radio_live_YOUR_API_KEY', $guzzle);

$radio = new Client(
    apiKey: null,
    baseUrl: 'https://radioapi.example.com',
);

$station = $radio->stations()->create([
    'name' => 'Chillwave Radio',
    'stream_url' => 'https://stream.example.com/live.mp3',
    'stream_metadata_provider' => 'azuracast',
    'stream_metadata_settings' => [
        'url' => 'https://station.example.com/api/nowplaying/chillwave',
        'genre' => 'Electronic',
    ],
    'music_provider' => 'auto',
    'nowplaying_access' => 'public',
    'nowplaying_history_enabled' => true,
]);

echo $station['uuid'];

$page = $radio->stations()->list([
    'status' => 'active',
    'per_page' => 25,
]);

$station = $radio->stations()->find('STATION_UUID');

$station = $radio->stations()->update('STATION_UUID', [
    'nowplaying_access' => 'private',
]);

// Disables the station. It does not hard-delete it.
$radio->stations()->delete('STATION_UUID');

$nowPlaying = $radio->nowPlaying('STATION_UUID');

echo $nowPlaying['artist'].' — '.$nowPlaying['song'];

use RadioApi\Client;

$publicRadio = Client::forPublicNowPlaying(
    'https://nowplaying.radioapi.example.com',
);

$nowPlaying = $publicRadio->nowPlaying('STATION_UUID');

$route = $radio->streamRouter()->create([
    'station_uuid' => 'STATION_UUID',
    'slug' => 'chillwave',
    'redirect_status_code' => 307,
]);

echo $route['url'];

$route = $radio->streamRouter()->create([
    'target_url' => 'https://cdn.example.com/chillwave.mp3',
    'slug' => 'chillwave-direct',
]);

$routes = $radio->streamRouter()->list(['status' => 'active']);
$route = $radio->streamRouter()->find('ROUTE_UUID');

$route = $radio->streamRouter()->update('ROUTE_UUID', [
    'is_active' => false,
]);

// Disables the route. It does not hard-delete it.
$radio->streamRouter()->delete('ROUTE_UUID');

use RadioApi\Exceptions\ApiException;

try {
    $radio->stations()->create([
        'name' => 'Missing stream URL',
    ]);
} catch (ApiException $exception) {
    if ($exception->errorCode === 'validation_error') {
        $fields = $exception->response['error']['fields'] ?? [];
    }
}
bash
composer