---
title: "Control embedded player with Player.js APIs"
slug: "control-embedded-player-with-playerjs-apis"
updated: 2024-07-24T15:10:40Z
published: 2024-07-24T15:10:40Z
---

> ## Documentation Index
> Fetch the complete documentation index at: https://help.tritondigital.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Control embedded player with Player.js APIs

> Programmatically control Omny.fm embeds on your website

The Omny Studio embeddable iframe player can be programmatically controlled on your own website using the player.js Javascript library.

Player.js allows you to interface with the iframe using a set of standardized methods and events across a wide range of supported rich media players.

[**Read the player.js documentation**](https://github.com/embedly/player.js#playerjs) to learn how to implement player.js on your website.

[**View demo code and example**](https://jsfiddle.net/hc1mnr6t/) to see it working live.

## Supported events

The Omny Studio embed player emits the following player.js events

- **play** - when the player is played
- **pause** - when the player is paused
- **ended** - when the player has finished playing the clip
- **timeupdate** - while the player is playing, updates the current time in seconds and the duration in seconds

## Supported methods

The Omny Studio embed player supports the following player.js methods

- **play()**- play the player
- **pause()** - pause the player
- **getPaused()**- returns if the player is paused
- **setCurrentTime()** - seeks to the time in seconds
- **getCurrentTime()**- returns the current position in seconds
- **getDuration()** - returns the duration in seconds
- **mute()**- mutes the player
- **unmute()** - unmutes the player
- **getMuted()**- returns if the player is muted
- **getVolume()** - returns the player's volume in %
- **setVolume()** - sets the player's volume in %

## iFrame autoplay policy

Due to recent [Google Chrome's autoplay policy changes](https://developers.google.com/web/updates/2017/09/autoplay-policy-changes), programmatically playing the embed using player.js might be restricted by default.

You can workaround the behaviour by adding `allow="autoplay"` to the iframe element which will delegate the play permission to the cross-domain iframe (assumes your site has autoplay permissions).

For example, your iframe code will look like

```plaintext
<iframe src="https://omny.fm/..." allow="autoplay"></iframe>
```

## Referrer policy

If your website includes a ["Referrer-Policy"](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy), specifically a value of `Referrer-Policy: same-origin`, then player.js might not work out of the box.

By default, for security reasons, the player.js library is designed to only send events to the parent window/document by specifying the `Window.postMessage()` `targetOrigin` parameter. The `targetOrigin` is assumed to be the `document.referrer`.

If the referrer policy `same-origin` is specified, then the Omny.fm embed player and player.js cannot automatically determine which origin it should send messages to.

You can overcome this issue by specifying a `referrer` URL parameter on the omny.fm embed player iframe URL with the domain of your website (including the protocol).

For example

```plaintext
<iframe src="https://omny.fm/shows/breakfast-with-john/baltic-bumpers/embed?style=cover&referrer=https://example.com" allow="autoplay; clipboard-write" frameborder="0" width="100%" height="180"></iframe>
```
