Skip to content
FrameworkStyle

Orientation lock

Screen orientation locking while fullscreen is active

Locks screen orientation while fullscreen is active. Add it explicitly to a feature list; it is not included in the default video presets.

API Reference

Configuration

Attributes and matching properties the provider element accepts. They exist only while this feature is selected.

PropTypeDefaultDetails
orientationLockTypeundefined | null | 'any' | 'landscape' | 'landscape-primary' | 'landscape-secondary' | 'natural' | 'portrait' | 'portrait-primary' | 'portrait-secondary''landscape'

State

PropertyTypeDetails
orientationLockType'any' | 'landscape' | 'landscape-primary' | 'landscape-secondary' | 'natural' | 'portrait' | 'portrait-primary' | 'portrait-secondary'

Actions

ActionTypeDetails
setOrientationLockType(value: undefined | null | 'any' | 'landscape' | 'landscape-primary' | 'landscape-secondary' | 'natural' | 'portrait' | 'portrait-primary' | 'portrait-secondary') => void

Usage

Selecting the feature adds it to the player.

import { createPlayer, features, MediaElement } from '@videojs/html';
import { videoFeatures } from '@videojs/html/video';

const { ProviderMixin } = createPlayer({
  features: [...videoFeatures, features.orientationLock],
});

class MyPlayer extends ProviderMixin(MediaElement) {}

customElements.define('my-player', MyPlayer);

Orientation type

The feature locks to landscape unless the provider sets another Screen Orientation API type. The value can change while the player is running; if the screen is already locked, it re-locks to the new type.

<my-player orientation-lock-type="portrait">
  <video slot="media" src="/video.mp4"></video>
</my-player>

The attribute only exists on a player that selected the feature. Setting it on an element built from videoFeatures alone does nothing.

Clearing the value restores landscape.

Selector

Pass selectOrientationLock to PlayerController to subscribe to the lock state. Returns undefined if the orientation lock feature is not configured.

import { createPlayer, features, MediaElement, selectOrientationLock } from '@videojs/html';
import { videoFeatures } from '@videojs/html/video';

const { PlayerController, context } = createPlayer({
  features: [...videoFeatures, features.orientationLock],
});

class OrientationToggle extends MediaElement {
  readonly #lock = new PlayerController(this, context, selectOrientationLock);
}

Unsupported browsers and rejected lock requests are ignored.