Delaying playback, modifying stream URLs and VAST adProvider
The Radioplayer web player offers an interface to modify the stream URLs and the VAST adProvider's tag
property before
playback. A popular use case is adding query parameters computed in other
<script>
tags.
Integrating into your web player
-
Add the configuration parameters to the configuration object.
playLocked
: Enables play back lockingnumberOfUnlockers
: How many unlocks are required for unlock to happen (defaults to 1 if unset)
<div data-widget-radioplayer> <script type="application/json"> { "...": "...", "playLocked": true, "numberOfUnlockers": 1 } </script> </div>
-
Create a new JavaScript file based on the sample file modifying-urls.js. Adapt to your purposes as necessary.
-
Add a
<script>
tag referencing your new file. It must appear a.) in the<head>
of your index.html and b.) before the tags for the Radioplayer web player.
After your change it should look like this:<!-- Must be before radioplayer.js! --> <script type="application/javascript" src="modifying-urls.js" ></script> <script type="module" src="/radioplayer.js"></script> <script nomodule defer src="/radioplayer.legacy.js"></script>
-
Test your console:
- Open it in a browser.
- Press play.
- Open the "Network" tab of your browser's developer tools
- Check if the HTTP request to your stream url contains the sample query param.
- Note that the sample file only modifies the first stream. If your web player is configured with multiple streams, you might not see a request to the modified stream URL.
- If your web player is configured with a VAST adProvider, a sample query param will be added to its tag url.
Guide for sample file
As showcased in the sample JavaScript file, playback locking and modifying playback configuration works like this:
- Your JS code registers an event handler (for event
radioplayer_readyToReceiveEvents
) - The web player dispatches the event once it has loaded all available stream URLs and adProvider configurations.
- Your event handler is triggered.
- Your JS code
-
- assigns methods from global variable: StreamModifierUtils
- reads the original stream URLs and adProvider configuration from a global variable
(
radioplayer_playbackConfigurationFromConsole
).
This contains a PlaybackConfiguration - modifies the stream URLs and VAST adProvider configuration using the example function.
- uses
sendNewStreamsToConsole
to inject the updated streams and adProvider configuration back into the Radioplayer console. - uses
unlockPlay
to notify the Radioplayer console that the script has finished executing and that it is safe to play. - if the user already clicked play, playback starts.
Alternative method of decorating the stream URL
An alternative method, which has been developed for publishers using Crossplan, can also be modified and used in conjunction with these methods. Following the instructions at Crossplan Integration, you will notice that rather than modifying the entire stream URL, you can call a method to pass in query parameters which will be decorated onto the stream before playback. This can be useful if you have one script which needs to make wholesale changes to the stream URL and additional scripts which might only need to append additional query parameters.
Note - If you do use this in conjunction with the other method detailed above,
please do not forget to update the console configuration to ensure it is
expecting the correct number of calls from the unlockPlay
method by setting
the numberOfUnlockers
variable
Using playback locking without modifying stream URLs
Modifying stream URLs requires playback locking. However, playback locking can
also be used on its own (without modifying stream URLs). If you only require
playback locking, wait until the web player is ready to receive events (see
above), then call the unlockPlay()
function in the
StreamModifierUtils
Usage in IFrame widget
Changing playback configuration and unlocking playback is also supported from within the IFrame widget.
The web player and the IFrame communicate via IFrameMessaging.
Integration steps
- Configure the web player properties
playLocked
,enableIframeMessaging
and optionallynumberOfUnlockers
.<div data-widget-radioplayer> <script type="application/json"> { "...": "...", "playLocked": true, "numberOfUnlockers": 1, "widgets": ["IF"], "iframeSrc": "url-of-your-iframe.html", "enableIframeMessaging": true } </script> </div>
- Create a new JavaScript file based on the IFrame sample file. Adapt to your purposes as necessary.
- Add the file via
<script>
to your IFrame HTML code.
Guide for IFrame sample file
As showcased in the sample IFrame sample file, playback locking and modifying playback configuration from within the IFrame works like this:
- Your JS code registers an event handler for events of type
message
. These are sent by the web player viawindow.postMessage()
. - The web player repeatedly sends ReadyForUnlockPlayMessages once it has loaded all available stream
URLs and adProvider configurations.
As shown in the sample file: Please ensure that your custom code only executes when receiving the first message - if that is necessary for your use case. - Your event handler is triggered.
- Your JS code in the IFrame
-
- reads the original stream URLs and adProvider configuration from the ReadyForUnlockPlayMessage's payload. This contains a PlaybackConfiguration.
- modifies the stream URLs and VAST adProvider configuration.
- creates a RequestPlaybackConfigurationUpdateMessage and sends it to the web player using
window.postMessage()
. - creates a RequestUnlockPlayMessage and sends it to the web player using
window.postMessage()
. - the web player updates its PlaybackConfiguration and unlocks playback.
- if the user already clicked play, playback starts.
Common pitfalls
- Modifying the AdsWizz, Triton or Google Tag Provider adProvider is not supported.
- The
<script>
tag of your JS code must appear a.) in the<head>
of your index.html and b.) before the tags for the Radioplayer web player. - Any URLs you modify must be valid URLs. Apply URL encoding if necessary.
- IFrame Messaging: The web player sends the ReadyForUnlockPlayMessage repeatedly, until playback is unlocked. Please ensure that your custom code only executes when receiving the first message - if that is necessary for your use case.
Technical details:
- The web player waits up to 7 seconds for the "unlock playback" event. After 7 seconds it automatically unlocks playback.
- If several
<script>
s modify the stream URLs, their order of execution must be managed by you. The web player does not offer any Tag Manager functionality. - Data exchange between the web player and your JavaScript file is done via JS events (see sample file).