Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Cloud Video
    • Overview
    • Control
    • Troubleshooting
      • Overview
      • IFrame
      • iOS
        • Getting started
        • Player initialization parameters
        • Player methods
        • Player state
        • Player events
  • Access management
  • Pricing policy
  • Audit Trails events
  • Release notes
  1. Video Player
  2. SDK
  3. JavaScript
  4. Player methods

Player methods

Written by
Yandex Cloud
Updated at October 9, 2024

You can manage Cloud Video Player using the following JavaScript SDK methods:

setSourcesetSource

Switches content.

Example of simple content switching:

player.setSource('https://runtime.video.cloud.yandex.net/player/...');

Where https://runtime.video.cloud.yandex.net/player/... is a link to playable content, e.g., https://runtime.video.cloud.yandex.net/player/video/vplvmyqsxi7dlwndvb4y. For more information, see Getting an embed code or link to a video and Getting an embed code or link to a broadcast.

Example of content switching with a specified starting position and disabled autoplay:

player.setSource({
    source: 'https://runtime.video.cloud.yandex.net/player/...',
    startPosition: 10,
    autoplay: false
});

This example uses an object of the following format as the parameter:

{
    /** @type {string} link to playable content */
    source,
    /**
     * @type {boolean} (optional) autoplay when switching to content.
     * By default, preserves the playback state used at time the method is called.
     * Autoplay may not work. See https://developer.chrome.com/blog/autoplay/
     * autoplay
     */
    autoplay,
    /** @type {number} (optional, the default value is 0) starting position in seconds */
    startPosition,
}

The method returns a promise which:

  • Gets the fulfilled status if switching is successful.
  • Gets the rejected status if switching fails. For example, if the content with a specified id was not found.

getStategetState

Returns the player state as an object in the format described in Player state.

Usage example:

var state = player.getState();

playplay

Starts playback.

The method returns a promise which:

  • Gets the fulfilled status if playback starts.
  • Gets the rejected status if playback fails.

pausepause

Pauses playback.

seekseek

Rewinds or fast forwards a video to a specific position, which is provided as the parameter.

Example of jumping to the 10th second:

player.seek(10);

setMutedsetMuted

Turns sound on/off.

The boolean type value is provided as the parameter.

Example of turning sound on:

player.setMuted(false);

setVolumesetVolume

Sets video volume level in the range from 0 (muted) to 1 (maximum volume).

Example:

player.setVolume(0.7);

on/onceon/once

Allows you to subscribe to player events.

If once is called, the subscription works only for the first triggering of the event; if on is called, for all triggerings.

These methods have the on(eventName, handler) and once(eventName, handler) signatures, respectively. The first parameter communicates the event name, the second communicates the handler.

The handler receives an object with the appropriate field from the player state.

Example of subscribing to all triggerings of the playback StatusChange event:

player.on('StatusChange', ({ status }) => {
    console.log(status);
});

offoff

Allows you to unsubscribe from the player events you subscribed to using the on or once methods.

The method has the off(eventName, handler) signature. The first parameter communicates the event name, the second communicates the handler you had used for subscription.

Example of unsubscribing from a handler function named handler for the playback StatusChange event:

player.off('StatusChange', handler);

destroydestroy

Destroys the player and frees up the resources.

Returns a promise, which enters the fulfilled state as soon as the operation is completed.

Usage example:

player.destroy();

See alsoSee also

  • Interface: PlayerSdkApi API reference

Was the article helpful?

Previous
Player initialization parameters
Next
Player state
Yandex project
© 2025 Yandex.Cloud LLC