<media-loading-indicator>

The <media-loading-indicator> component indicates when the media is buffering. By default, this element is hidden and will only be shown when media loading is stalled.

The component will be updated automatically based on media state and the functionality can be configured.

  • The loadingdelay attribute to have the loading indicator wait the provided amount of milliseconds before showing.
  • What is being displayed can be configured via the loading slot.
<media-controller>
  <video
    slot="media"
    src="https://stream.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/low.mp4"
    playsinline
    muted
  ></video>
  <media-loading-indicator slot="centered-chrome"></media-loading-indicator>
</media-controller>

You can modify the contents of the <media-loading-indicator> component using slots. This is useful if you’d like to use your own custom loading indicator instead of the default one provided by media-chrome.

Here is an example with custom SVGs:

<media-controller>
  <video
    slot="media"
    src="https://stream.mux.com/A3VXy02VoUinw01pwyomEO3bHnG4P32xzV7u1j1FSzjNg/low.mp4"
    playsinline
    muted
  ></video>
  <media-loading-indicator slot="centered-chrome">
    <svg slot="icon" viewBox="-12 -15 48 60">
      <path d="M0 0h4v10H0z">
        <animateTransform
          attributeType="xml"
          attributeName="transform"
          type="translate"
          values="0 0; 0 20; 0 0"
          begin="0"
          dur="0.6s"
          repeatCount="indefinite"
        />
      </path>
      <path d="M10 0h4v10h-4z">
        <animateTransform
          attributeType="xml"
          attributeName="transform"
          type="translate"
          values="0 0; 0 20; 0 0"
          begin="0.2s"
          dur="0.6s"
          repeatCount="indefinite"
        />
      </path>
      <path d="M20 0h4v10h-4z">
        <animateTransform
          attributeType="xml"
          attributeName="transform"
          type="translate"
          values="0 0; 0 20; 0 0"
          begin="0.4s"
          dur="0.6s"
          repeatCount="indefinite"
        />
      </path>
    </svg>
  </media-loading-indicator>
</media-controller>

Configuring the loading indicator

Section titled Configuring the loading indicator

It’s possible to change how long the loading indicator waits before showing itself when the media state changes to loading.

There are 3 ways of changing the delay: an attribute, a property, or a CSS variable. All values are in milliseconds.

<media-loading-indicator loadingdelay="1000"></media-loading-indicator>
const loadingIndicator = document.querySelector('media-loading-indicator');

loadingIndicator.loadingDelay = 1000;
media-loading-indicator {
 --media-loading-indicator-transition-delay: 1000ms;
}

Making the loading indicator always be visible

Section titled Making the loading indicator always be visible

It’s possible to keep the loading indicator always visible via a CSS variable.

media-loading-indicator {
 --media-loading-indicator-opacity: 1;
}

See the Customize Icons section above for this in action.

The <media-loading-indicator> will be updated with media state attributes depending on the media and playback states.

You can use these attributes to apply custom styles to your <media-loading-indicator>. For example, if the media is loading but you want the indicator to be semi-transparent, you can change the opacity like so:

media-loading-indicator[medialoading]:not([mediapaused]) {
  --media-loading-indicator-opacity: 0.75;
}
NameDescription
iconThe element shown for when the media is in a buffering state.
NameTypeDescription
loadingdelaystringSet the delay in ms before the loading animation is shown.
mediacontrollerstringThe element `id` of the media controller to connect to (if not nested within).

The media UI attributes will be set automatically by the controller if they are connected via nesting or the mediacontroller attribute. Only set these attributes manually if you know what you're doing.

NameTypeDescription
mediapausedboolean Present if the media is paused.
medialoadingboolean Present if the media is loading.
NameDefaultDescription
--media-primary-colorrgb(238 238 238)Default color of text and icon.
--media-icon-colorvar(--media-primary-color, rgb(238 238 238))fill color of button icon.
--media-control-displayvar(--media-loading-indicator-display, inline-block)display property of control.
--media-loading-indicator-displayinline-blockdisplay property of loading indicator.
--media-loading-indicator-opacity0opacity property of loading indicator. Set to 1 to force it to be visible.
--media-loading-indicator-transition-delay500mstransition-delay property of loading indicator. Make sure to include units.
--media-loading-indicator-icon-widthwidth of loading icon.
--media-loading-indicator-icon-height100pxheight of loading icon.