Transmit the video status data
To improve the quality of video search and playback, we require information about the video's status. For example, the time when the video started, stopped, or was rewound. It's also important to pass on information about errors that occurred while the video was playing.
Events that relate to video status
To pass on data about a video's status, use the postMessage function for each event that occurs in the player (for example, when the video starts playing). Call the window.parent.postMessage
function in JavaScript. Pass the name of the event along with the event parameters (for example, the progress bar position) as arguments.
Note
Please note that the postMessage
function must be called for the parent object — window.parent
. This is because the video is placed in a separate frame (in the iframe
element) rather than on the main Yandex search results page.
window.parent.postMessage({
event: <Event name>,
// additional event parameters
}, '*');
To display the video player in the video search app for TV and in your browser, you need to transmit the mandatory events and their parameters. Transmitting additional events makes it easier for users to interact with the player. Signals help us rank videos better.
Event |
Description |
Event parameter |
Mandatory |
||
|
Player initialization. |
— |
|
Stop playing. |
|
|
Clip viewed through to the end. |
|
|
Start or continue playing after a pause. |
|
|
Video plays (this event is repeated multiple times). |
|
|
Error playing video, the video is unavailable. |
|
|
Start of ad display. |
See Examples* Note The ad parameters can be sent as a separate |
|
End of ad display. |
|
|
First video frame display. Note If ads are played before the video, send the event when the first frame of the video shows up after the end of the ad unit. |
|
Additional |
||
|
Jump back in video |
|
|
Continue playing video. |
Note The |
|
Turn sound on, off, or change the volume. |
Similar to the native volumechange event used with the |
|
Buffering of the video or a video segment has started. |
|
|
A video segment has loaded. |
|
|
Skips the ad. Doesn't substitute |
|
|
Change the video quality |
|
|
Change the playback rate. |
|
|
Switch the player to fullscreen or exit fullscreen. |
|
|
The player is now loaded and ready for use (data and player API have loaded) |
|
|
Clickout to ads (service) from the player. |
|
|
Send this event whenever a video is replaced inside the |
|
|
An error occurred while trying to switch to fullscreen or exit fullscreen. |
|
|
List of available quality values. |
|
* Examples of data for the adShown event
When an ad unit begins playback at the 30th second of the video and consists of two ads, where the first ad is 15 seconds and can be skipped, and the second ad is 25 seconds and can't be skipped, the adShown
event should include the following:
{
count: 2,
time: 30,
ads: [
{
duration: 15.0,
skip: 1
},
{
duration: 25.3,
skip: 0
}
]
}
For an ad unit with a single ad that plays at the very beginning of the video (preroll
), lasts 45 seconds, and can't be skipped:
{
count: 1,
time: 0,
ads: [
{
duration: 45.5,
skip: 0
}
]
}
Below is an example of data that's transferred when a video starts. When a user clicks on the Play button on the player, the window.parent.postMessage
function is called along with the necessary parameters.
// Send a message when the video starts playing
window.parent.postMessage({
event: 'started',
duration: 30,
time: 5 // If the video continues playing starting at 5 seconds
}, ' *');
Error notifications
The player must pass the following error codes to the window.parent.postMessage
function so that we find out about any problems that occur:
Error code |
Description |
Video unavailable |
|
101 |
Video deleted. |
102 |
The videoclip or account has been blocked. |
103 |
The video doesn't exist or the URL isn't supported. |
100 |
Other situations when a video is inaccessible. |
Restricted access to videoclip |
|
151 |
Insufficient video viewing rights. |
152 |
Not permitted to play video on other sites. |
153 |
Not permitted to play video in current region. |
154 |
Restricted access that requires the user to confirm something, for example, their age or a login attempt. |
155 |
The video isn't available because the service flagged the request as coming from a bot. |
156 |
The video requires a subscription to view. |
150 |
Other video viewing restrictions. |
Other |
|
5 |
Player malfunction (for example, an error with the HTML player). |
0 |
Misc. errors. |
If the video that opens in the player was deleted, the error message may look like this:
// Send an error message
window.parent.postMessage({
event: 'error',
time: 0,
code: '101'
}, '*');
Support parameters in player URL
For a smoother video experience on Smart TVs and browsers, add these parameters to the player URL:
Parameter |
Description |
Possible values |
Mandatory |
||
|
Autoplay |
|
|
Controls how interactive player elements are displayed on devices with Smart TV. |
This parameter controls the display of all elements that can only be clicked on with a mouse. These include the progress bar, drop-down lists of seasons and series, buttons for selecting video quality, the video control menu, and other elements. If these elements are hidden automatically, it creates a better viewing experience on TVs. |
|
Load muted videos. |
|
|
Display control elements (progress bar, quality change, and others) in the video player. |
|
|
The timestamp where the video should start playing. |
The example shows the video starting at 10:00 (600 c = 10 min). |
Managing the player
Player control commands are sent to the iframe
from the outside window using the postMessage function. To receive messages inside the iframe
, you need to subscribe to the message
event. The command format is a JSON object with the mandatory method
field.
Team |
Description |
|
Start or continue playing video.
|
|
Pause.
|
|
Jump to an absolute time value.
|
|
Set volume.
|
|
Disable sound.
|
|
Enable sound.
|
|
Set the video quality.
|
|
Method to change the video inside the player without redrawing the entire
|
|
Method to trigger video buffering before playback.
|
|
Method to switch to fullscreen.
|
|
Method to exit fullscreen.
|
Example of launching a video using a command
window.addEventListener('message', function (event) {
if (event.data.method === 'play') {
document.getElementById('video').play();
}
});
Answer format
For feedback on command execution, use video status events.