---
title: selectPiP
description: Select the picture-in-picture state slice from the player store
---

import UtilReference from "@/components/docs/api-reference/UtilReference.astro";
import DocsLink from "@/components/docs/DocsLink.astro";
import FrameworkCase from "@/components/docs/FrameworkCase.astro";

<FrameworkCase frameworks={["react"]}>
Pass `selectPiP` to <DocsLink slug="reference/use-player">`usePlayer`</DocsLink> to subscribe to picture-in-picture state. Returns `undefined` if the PiP feature is not configured.
</FrameworkCase>

<FrameworkCase frameworks={["html"]}>
Pass `selectPiP` to <DocsLink slug="reference/player-controller">`PlayerController`</DocsLink> to subscribe to picture-in-picture state. Returns `undefined` if the PiP feature is not configured.
</FrameworkCase>

The returned state includes whether PiP is active and its availability on the current platform.

<FrameworkCase frameworks={["react"]}>
```tsx
import { usePlayer } from '@videojs/react';
import { selectPiP } from '@videojs/core/dom';

function PiPButton() {
  const pip = usePlayer(selectPiP);
  if (!pip || pip.availability !== 'available') return null;

  return (
    <button onClick={pip.toggle}>
      {pip.active ? 'Exit PiP' : 'Picture-in-Picture'}
    </button>
  );
}
```
</FrameworkCase>

<FrameworkCase frameworks={["html"]}>
```ts
import { createPlayer, features, MediaElement } from '@videojs/html';
import { selectPiP } from '@videojs/core/dom';

const { PlayerController, context } = createPlayer({ features: features.video });

class PiPButton extends MediaElement {
  #pip = new PlayerController(this, context, selectPiP);
}
```
</FrameworkCase>

<UtilReference util="selectPiP" />
