enes

Media Player

A media player plays a video with Fluent transport controls: a seek bar with the time, volume, subtitles, skip buttons, playback speed, picture-in-picture and full screen. Video.js runs the playback, the keyboard shortcuts and the gestures underneath.

Usage

<script>
	import { MediaPlayer } from 'fluentui-svelte';
</script>

<MediaPlayer src="video.mp4" poster="poster.jpg" />

Deferred loading

deferred shows the poster with a large play button and holds back the player, Video.js and the media until that button is pressed: a page full of videos nobody plays downloads none of them. With click loading starts on the press, with intent once the pointer or the focus reaches the button, and with visible as soon as the player scrolls into view.

Compact layout

layout="compact" fits the play button, the seek bar and the essential buttons into one row, ideal for cards and small embeds.

Narrow players

Below 26rem of width, the standard layout trims itself down to the volume, play, picture-in-picture and full screen buttons.

Vertical volume

volumeOrientation="vertical" stands the volume slider upright above its button, handy when the row is short on space.

Vertical video

A vertical video grows as tall as its width allows. Give the player a width and match aspectRatio to the media, here 9 / 16, to reserve its space while it loads. At that width only the essential buttons remain.

Subtitles

Pass WebVTT files in tracks. A single track gets a toggle button, and several get a menu to choose from.

Subtitles appearance

subtitlesAppearance="translucent" swaps the acrylic panel for light text on a dark veil, close to native subtitles. subtitlesSize picks small, medium or large.

Skip buttons and playback speed

skipBackward accepts 10 or 15 seconds and skipForward 10, 15 or 30, while 0 hides either button. playbackRates lists the speeds of the more options menu; an empty list removes them.

Previous and next

onPrevious and onNext add previous and next buttons around the playback controls. The system media controls, picture-in-picture included, trigger them as well.

1 / 4 · Mux sample

Custom controls and menu items

showRepeat adds the built-in repeat button, bound to loop. startContent, centerContent and endContent place your own controls in each group of the row, while moreContent extends the more options menu; all of them receive the Video.js store. MediaPlayerButton gives a control the built-in look and tooltip, and the optional class hides it in narrow players.

Repeat: off · Like: off · Chapters: off · Shared: 0

Controlling the player from code

Bind playerRef to reach the Video.js store and drive the player through its state and actions, such as seek, play, pause or setPlaybackRate.

Texts and translations

labels sets the names and tooltips of the controls, menus and messages. Missing texts fall back to English, and custom controls receive the final set to name themselves consistently. Every player on this page follows the language of the site.

Component Props

NameTypeDefaultDescription
srcstringThe URL of the media to play.
posterstringThe image shown until the media plays.
tracksMediaPlayerTrack[]The text tracks of the media: subtitles, captions or chapters.
layout'standard' | 'compact''standard'How the transport controls are laid out.
deferred'click' | 'intent' | 'visible'Shows a light splash in place of the player, with the poster and a play button, and loads the player, its scripts and the media only when the play button is pressed. Video.js and the media download nothing before.
aspectRatiostring'16 / 9'The shape of the player until its media loads, and of the splash of a deferred player, as a CSS aspect-ratio. Match it to the media and nothing moves once the video arrives.
volumeOrientation'horizontal' | 'vertical''horizontal'The direction of the volume slider in its popup.
autoHideControlsbooleantrueHides the transport controls while the media plays and the user rests, and shows them again on any activity. false keeps them on screen.
autoHideWhenPausedbooleanHides the transport controls of a paused media too, once the user rests. Without it, a pause keeps them on screen.
subtitlesAppearance'acrylic' | 'translucent''acrylic'How the subtitles look.
subtitlesSize'small' | 'medium' | 'large''medium'The size of the subtitles text. A narrow player takes one step down.
loop bindablebooleanPlays the media again from the start when it ends. The repeat button toggles it.
showRepeatbooleanShows a repeat button, which toggles loop.
skipBackward0 | 10 | 1510How many seconds the skip back button rewinds. 0 hides the button.
skipForward0 | 10 | 15 | 3030How many seconds the skip forward button advances. 0 hides the button.
playbackRatesnumber[][0.5, 0.75, 1, 1.25, 1.5, 1.75, 2]The speeds of the more options menu. An empty list removes the playback speed group.
onPrevious() => voidShows a previous button and calls this when it is pressed, or when the system media controls ask for the previous track.
onNext() => voidShows a next button and calls this when it is pressed, or when the system media controls ask for the next track.
startContentSnippet | ComponentCustom controls at the start of the button row, after the volume and subtitles buttons.
centerContentSnippet | ComponentCustom controls in the middle of the button row, after the next button.
endContentSnippet | ComponentCustom controls at the end of the button row, before the picture-in-picture button.
moreContentSnippet | ComponentCustom items for the more options menu, after the playback speed group. Use the Menu items.
labelstring'Media player'The accessible name of the player.
labelsPartial<MediaPlayerLabels>The texts of the controls, their tooltips and menus. The ones left out fall back to English.
ref bindableHTMLVideoElement | nullThe DOM reference of the native video element. The other attributes of the player are applied to it.
playerRef bindableVideoPlayerElementThe <video-player> element of Video.js. Its store holds the state and the actions of the player.
wrapperAttributesHTMLAttributesThe attributes to spread on the element that draws the player.
childrenSnippetExtra <source> or <track> elements for the video.
HTMLVideoAttributes without src, poster, controls, children, loop

MediaPlayerButton

NameTypeDefaultDescription
labelstringThe accessible name of the button, also shown in its tooltip.
tooltipPlacementPlacement'top'Where the tooltip is placed relative to the button.
hideTooltipbooleanKeeps the tooltip closed, for a button whose popup is open.
ref bindableHTMLButtonElement | nullThe DOM reference of the button element.
childrenSnippetThe icon of the button.
ButtonProps<'button'> without ref, children, appearance
Edit this Doc View as Markdown