Skip to content

ReferenceMedia

LazyAudio

Unstable

Audio media that picks the media component for its source and loads only that component's code

The audio counterpart of LazyVideo: reads src, renders the media component that plays it, and loads that component’s code only once the source is known.

Import

npm install @videojs/react @videojs/mux-audio @videojs/spotify-audio @videojs/soundcloud-audio @videojs/mixcloud-audio
import { LazyAudio } from '@videojs/react/media/lazy-audio';

Sources

Source Resolves to Loads
Audio and video files Native <audio> Nothing
HLS HlsAudio The SPF HLS engine
HLS where there’s no MSE Native <audio> Nothing
stream.mux.com MuxAudio Mux Audio
Spotify SpotifyAudio The Spotify embed
SoundCloud SoundCloudAudio The SoundCloud widget
Mixcloud MixcloudAudio The Mixcloud widget

A source that matches none of these, including YouTube, Vimeo, and DASH, renders nothing and logs an error in development.

Custom media

createLazyAudio builds a LazyAudio from a list of media, tried in order, the same way createLazyVideo does. The built-in media are audio, hlsAudio, muxAudio, spotifyAudio, soundcloudAudio, and mixcloudAudio, each imported from @videojs/react/media/lazy/ plus its kebab-case name.

import { audio } from '@videojs/react/media/lazy/audio';
import { createLazyAudio } from '@videojs/react/media/lazy/create';
import { muxAudio } from '@videojs/react/media/lazy/mux-audio';

const MuxLazyAudio = createLazyAudio([audio, muxAudio]);

LazyAudio takes the same src, type, preferPlayback, and preload options as LazyVideo, and loads and passes props on the same way. See LazyVideo for its behavior and API reference.

Examples

Basic Usage

import { LazyAudio } from '@videojs/react/media/lazy-audio';

import './BasicUsage.css';

export default function BasicUsage() {
  return <LazyAudio className="react-lazy-audio-basic" src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/audio.m4a" controls preload="metadata" />;
}