Knowledge base
1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
This guide explains how to maintain control over your MP3/AAC or HLS Streaming Radio streams by activating unique key (token) protection to decide, for example, whether a listener can listen to your radio or not.
Introduction
- The principle is simple: with each connection, you will make a request to the Infomaniak API, which will return a unique token with a limited and customizable lifespan. This token will authorize anyone who possesses it to consume the stream during this period.
- You can protect an MP3/AAC or HLS stream independently of each other (the same applies to geolocation).
- Enabling the restriction involves changing the stream configuration, which may take a few minutes to be replicated across the servers.
Protect an audio stream with a unique key
To do this, simply go to the restriction settings and activate token protection on the stream you wish to secure:
- Click here to access the management of your product on the Manager Infomaniak (need help?).
- Click directly on the name assigned to the product in question.
- Click on the name of the audio stream in question.
- Click on Restrictions in the left sidebar.
- Select HLS if necessary.
- Click on the action menu â‹® located to the right of the relevant item.
- Click on Token Restriction:
Enable the protection next.
Warning, when you activate this option, access to the stream will be instantly blocked for new connections. Adapt your Players to take into account the restriction, as illustrated in the example below:
Create a Radio API Token
To access the Radio API, you must first authenticate using an application token. This step only needs to be done once. To create this application token, refer to this other guide.
The scope is radio and with unlimited lifetime to avoid having to regenerate a code on a regular basis. Once the token is generated, copy it to paste it into the example below.
PHP usage example
For MP3/AAC or HLS, the code can be quite similar, only the URL called in POST changes in its form.
Paste the generated token below instead of the one indicated:
if (!defined('API_TOKEN')) {
define('API_TOKEN', 'AYF5lSh3c7Xy5974Fs12RTkTThujT-L9R4Xk2ZfGyP6sV7QqJ1oC3jD8nFtKzIxUeMw5oNzR6');
}
/**
* Fonction générique pour executer des requêtes cURL
*
* @param string $method Méthode HTTP (GET, POST, PUT, etc...)
* @param string $url Url de l'api a requêter
* @param array $headers Liste des en-têtes HTTP (l'autorisation doit être passée ici avec un ['Authorization: Bearer ']
* @param array $payload Un tableau contenant les données pour créer un token
* @return mixed
*/
function request(string $method, string $url, array $headers = [], array $payload = []): mixed{
// prepare options array
$opts = [
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
CURLOPT_CUSTOMREQUEST => strtoupper($method),
];
// add payload if relevant
if ($payload && $method !== 'GET') {
$opts[CURLOPT_POSTFIELDS] = json_encode($payload);
}
$ch = curl_init();
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
if(curl_errno($ch)){
throw new Exception(curl_error($ch));
}
$data = json_decode($result, true);
if ($data['result'] === 'error') {
throw new Exception($data['error']['description'] ?? 'an error occured');
}
return $data['data'];
}
We are going to create the token. The URL for creating the token breaks down as follows:
- For an MP3 / AAC stream
POST https://api.infomaniak.com/1/radios/acl/streams/mountpoint.mp3/token
Example to protect https://newradiotest.ice.infomaniak.ch/newradiotest-128.aac
the route will be: https://api.infomaniak.com/1/radios/acl/streams/newradiotest-128.aac/token
- For an HLS stream
POST https://api.infomaniak.com/1/radios/acl/hls_streams/<stream>/token
Example to protect https://myradiostream.radiohls.infomaniak.com/myradiostream/manifest.m3u8
the route will be: https://api.infomaniak.com/1/radios/acl/hls_streams/myradiostream/token
Example for MP3/AAC, make sure to adjust:
$token = request(
'POST',
'https://api.infomaniak.com/1/radios/acl/streams/newradiotest-128.aac/token',
// en-tête d'authorization
[
'Authorization: Bearer ' . API_TOKEN,
'Content-Type: application/json',
],
/**
* payload pour créer le token, vous pouvez passer les valeurs suivantes
* window | 300 | optionnel | durée de validité du token (default: 5 minutes)
*/
[
'window' => 3600, // 1h validity
]
);
It is important to note that if this code is generated at the time of page loading, the listener will have "window" seconds to start playing the stream. Beyond this delay, the token will expire, and the stream will no longer be able to be launched unless the page is reloaded. Depending on your needs and use case, it will be necessary to adjust this delay in the best possible way.
You will also need to replace the playback URL of your stream below with the one indicated, while keeping the $token
parameter at the end. Finally, display the Player (here a simple html5 tag, but you can of course add any overlay afterwards, the token being passed in the $_GET
parameters of the url).
$streamUrl = "https://newradiotest.ice.infomaniak.ch/newradiotest-128.aac?$token";
echo "<audio controls=""><source src="$streamUrl"></audio>";
This guide details the configuration of a Player for your Streaming Radio Infomaniak.
Prerequisites
Configuring the options for the Infomaniak Player
Once you have linked your stream to your Player and your Player is created:
- Click here to access the management of your product on the Manager Infomaniak (need help?).
- Click directly on the name assigned to the relevant product.
- Click on My players in the left sidebar.
- Click on the name of the Player to configure (or create a new player):
1. Appearance tab
This is where you can choose the player size (large, medium, mini, or multi-radio player) and its display percentage.
You can customize the colors of the background, buttons, and text:
A toggle switch allows you to enable or disable the display of the tracks broadcast, with or without their broadcast times:
- Take note of the details on this subject at the end of this guide.
The Player can display:
- an illustration representing the album cover, or a substitute image if it is not available,
- a static image (3 MB max.),
- your radio's logo, to customize here:
- an audio spectrum visualization (Spectrogram / Spectrum).
2. Tab Broadcast
This is where you can link your radio streams (HLS or not) to your Player being configured.
Refer to this other guide regarding the options offered concerning live management:
3. Tab Thumbnails
This is where you can upload images that will be visible when the stream is loading, or unavailable/restricted.
4. Tab Player Information
This is where you can name your Player and decide to show or hide:
- the title and the artist instead of the radio name,
- the number of listeners,
- the Infomaniak logo.
5. Tab Sharing Options
A toggle switch allows you to enable or disable certain services like Facebook. Once enabled, a share button for these services will be visible on your Player:
Broadcast history details (tab #1)
The broadcast history allows you to re-listen to the music broadcast (between 1 and 40) if your stream is of type HLS only (you can then define a buffer memory ranging from 25 seconds to 2 hours):
The rewind and replay feature is not enabled by default: it remains optional to comply with the restrictions of certain countries or radios. Once activated, the radio manager can choose which streams will be available for broadcast (see tab #2 above), while the listener can select the listening quality in the Player:
Position & integration of the broadcast history
The list is viewable as follows:
- directly under the Player,
- on the Player,
- or movable within the integration of your website…
Indeed, it is possible to display the history in a second iframe, separate from the main Player. Example URL for the Player:https://player-radio.infomaniak.com/2/prod/super/7cbaa24a-3510-47a4-b41e-b99218bfd507
And for the offloaded history:https://player-radio.infomaniak.com/2/prod/history
The two iframes must be integrated on the same page and communicate with each other to update the history or play a previously broadcasted title.
A second integration mode allows you to display an autonomous history, without a main iframe. Simply add the ID of the Player to the URL:https://player-radio.infomaniak.com/2/prod/history/7cbaa24a-3510-47a4-b41e-b99218bfd507
This mode is suitable, for example, for users of another Player who wish to display only the history of tracks.
This guide explains how to transfer the audio streams present on one of your Infomaniak Streaming Radio to another of your radios, present in the same Organization.
Refer to this other guide to transfer all streams from a Streaming Radio to a new owner.
Transfer audio streams
To do this:
- Click here to access the management of your product on the Infomaniak Manager (need help?).
- Click directly on the name assigned to the product in question.
- Click on the action menu â‹® located to the right of the relevant item.
- Choose Transfer:
- Search for and validate the name of the other radio that you own within the same Organization.
- Confirm the transfer:
Refresh the Manager pages if necessary to update the displayed information.