Video ComponentType-safe video element component with browser policy enforcement.
Navigation

Video Component

Type-safe video element component with browser policy enforcement.

Import

import codes.yousef.summon.components.media.Video
import codes.yousef.summon.components.media.VideoSource

Overview

The Video component provides a type-safe video element that maps Kotlin booleans to proper HTML5 video attributes and enforces browser policies (e.g., autoplay requires muted).

Function Signature

@Composable
fun Video(
    src: String? = null,
    sources: List<VideoSource> = emptyList(),
    poster: String? = null,
    autoplay: Boolean = false,
    muted: Boolean = false,
    loop: Boolean = false,
    controls: Boolean = true,
    playsInline: Boolean = true,
    preload: String = "metadata",
    crossorigin: String? = null,
    width: String? = null,
    height: String? = null,
    ariaLabel: String? = null,
    modifier: Modifier = Modifier()
)

Parameters

ParameterTypeDefaultDescription
srcString?nullPrimary video source URL (ignored if sources is provided)
sourcesList<VideoSource>emptyList()List of video sources for format fallback
posterString?nullURL to poster image displayed before playback
autoplayBooleanfalseWhether to start playing automatically (requires muted)
mutedBooleanfalseWhether the video is muted
loopBooleanfalseWhether to loop the video
controlsBooleantrueWhether to show playback controls
playsInlineBooleantrueWhether to play inline on mobile (not fullscreen)
preloadString"metadata"Preload strategy: "none", "metadata", or "auto"
crossoriginString?nullCORS setting: "anonymous" or "use-credentials"
widthString?nullVideo width (can also use modifier)
heightString?nullVideo height (can also use modifier)
ariaLabelString?nullAccessibility label for the video
modifierModifierModifier()Styling modifier for the video element

Browser Autoplay Policy

Modern browsers require videos to be muted for autoplay to work. If you set autoplay = true with muted = false, the component will automatically set muted = true to comply with browser policies and log a warning.

VideoSource

Data class for defining multiple video sources with format fallback:

data class VideoSource(
    val src: String,   // URL to the video file
    val type: String   // MIME type (e.g., "video/mp4", "video/webm")
)

Examples

Basic Usage

Video(
    src = "https://example.com/video.mp4",
    modifier = Modifier().width("100%").maxWidth("800px")
)

Autoplay Hero Video

// Muted is auto-enforced for autoplay
Video(
    src = "https://example.com/hero.mp4",
    autoplay = true,
    loop = true,
    controls = false,
    poster = "https://example.com/poster.jpg"
)

Multiple Sources for Format Fallback

Video(
    sources = listOf(
        VideoSource("video.webm", "video/webm"),
        VideoSource("video.mp4", "video/mp4")
    ),
    controls = true
)

Responsive Video

Video(
    src = "video.mp4",
    modifier = Modifier()
        .responsiveMedia()
        .aspectRatio(16, 9)
)

Pause on Scroll

Box(modifier = Modifier().pauseOnScroll()) {
    Video(
        src = "hero-video.mp4",
        autoplay = true,
        muted = true,
        loop = true
    )
}

MIME Type Inference

When using src instead of sources, the component automatically infers the MIME type from the file extension:

ExtensionMIME Type
.mp4video/mp4
.webmvideo/webm
.oggvideo/ogg
.movvideo/quicktime

Accessibility

  • Use ariaLabel to provide descriptive text for screen readers
  • Always include controls = true unless the video is purely decorative
  • Consider providing captions for videos with spoken content

See Also

Architected in Kotlin. Rendered with Materia. Powered by Aether.
© 2026 Yousef.