SkillAgentSearch skills...

ComposeMediaPlayer

Compose Media Player is a video player library designed for Compose Multiplatform, supporting multiple platforms including Android, macOS, Windows, Linux, iOS and Compose Web

Install / Use

/learn @kdroidFilter/ComposeMediaPlayer

README

🎥 Compose Media Player

<img src="/assets/banner.jpg" style="border-radius: 10px;"/>

Maven Central License: MIT Kotlin Platforms Contributions welcome Documentation GitHub Workflow Status GitHub last commit

Supported by

JetBrains logo.

Compose Media Player is a video player library designed for Compose Multiplatform, supporting multiple platforms including Android, macOS, Windows, and Linux. It is the first fully functional multiplatform video player for Compose for Desktop that requires no additional software installations. The library leverages:

  • GStreamer for Linux
  • Media Foundation for Windows
  • AVPlayer for macOS and iOS
  • Media3 for Android
  • HTML5 Player for WASMJS

Table of Contents

🚀 Live Demo

Try the online demo here : 🎥 Live Demo

✨ Features

  • Multiplatform Support: Works seamlessly on Android, macOS, Windows, Linux and Compose Web (Wasm).
  • File and URL Support: Play videos from local files or directly from URLs.
  • Media Controls: Includes play, pause, loop toggle, volume control, playback speed, loop playback and timeline slider.
  • Initial Playback Control: Choose whether videos automatically play or remain paused after opening.
  • Custom Video Player UI: Fully customizable using Compose Multiplatform, with support for custom overlays that display even in fullscreen mode.
  • Audio Levels: Displays left and right audio levels in real time.
  • Fullscreen Mode: Toggle between windowed and fullscreen playback modes.
  • Error handling Simple error handling for network or playback issues.

✨ Supported Video Formats

| Format | Windows | Linux | macOS & iOS | Android | WasmJS | |--------|-------------------------------------------------------------------------------------------------------------------|-------------------|-----------------------------------------------------------------------------|-----------------|-------------------| | Player | MediaFoundation | GStreamer | AVPlayer | Media 3 | HTML5 Video | | MP4 (H.264) | ✅ | ✅ | ✅ | ✅ | ✅ | | AVI | ❌ | ✅ | ❌ | ❌ | ❌ | | MKV | ❌ | ✅ | ❌ | ✅ | ❌ | | MOV | ✅ | ✅ | ✅ | ❌ | ✅ | | FLV | ❌ | ✅ | ❌ | ❌ | ❌ | | WEBM | ❌ | ✅ | ❌ | ✅ | ✅ | | WMV | ✅ | ✅ | ❌ | ❌ | ❌ | | 3GP | ✅ | ✅ | ✅ | ✅ | ❌ |

🔧 Installation

To add Compose Media Player to your project, include the following dependency in your build.gradle.kts file:

dependencies {
    implementation("io.github.kdroidfilter:composemediaplayer:<version>")
}

📊 Compatibility Table

| Library Version | Kotlin Version | Compose Version | |-----------------|----------------|-----------------| | 0.8.6 | 2.3.0 | 1.9.3 | | 0.8.3 | 2.2.20 | 1.9.0 | | 0.7.11 | 2.2.0 | 1.8.2 | | 0.7.10 | 2.1.21 | 1.8.2 |

🚀 Getting Started

Initialization

Before using Compose Media Player, you need to create a state for the video player using the rememberVideoPlayerState function:

val playerState = rememberVideoPlayerState()

Displaying the Video Surface

After initializing the player state, you can display the surface of the video using VideoPlayerSurface:

// Video Surface
Box(
    modifier = Modifier.weight(1f).fillMaxWidth(),
    contentAlignment = Alignment.Center
) {
    VideoPlayerSurface(
        playerState = playerState,
        modifier = Modifier.fillMaxSize()
    )
}

Content Scaling

[!WARNING] Content scaling support is experimental. The behavior may vary across different platforms.

You can control how the video content is scaled inside the surface using the contentScale parameter:

VideoPlayerSurface(
    playerState = playerState,
    modifier = Modifier.fillMaxSize(),
    contentScale = ContentScale.Crop // Default is ContentScale.Fit
)

Available content scale options:

  • ContentScale.Fit (default): Scales the video to fit within the surface while maintaining aspect ratio
  • ContentScale.Crop: Scales the video to fill the surface while maintaining aspect ratio, potentially cropping parts
  • ContentScale.FillBounds: Stretches the video to fill the surface, may distort the aspect ratio
  • ContentScale.Inside: Similar to Fit, but won't scale up if the video is smaller than the surface
  • ContentScale.None: No scaling applied

Surface type

[!WARNING] Surface type parameter is supported only for Android target.

Available surface type options:

  • SurfaceType.SurfaceView: uses SurfaceView for the player view, which is more performant for video playback but has limitations in terms of composability and animations.
  • SurfaceType.TextureView (default): uses TextureView for the player view, which allows for more complex composable layouts and animations.
VideoPlayerSurface(
    playerState = playerState,
    modifier = Modifier.fillMaxSize(),
    surfaceType = SurfaceType.SurfaceView // Default is SurfaceType.TextureView
)

Custom Overlay UI

You can add a custom overlay UI that will always be visible, even in fullscreen mode, by using the overlay parameter:

VideoPlayerSurface(
    playerState = playerState,
    modifier = Modifier.fillM
View on GitHub
GitHub Stars384
CategoryCustomer
Updated5d ago
Forks29

Languages

Kotlin

Security Score

100/100

Audited on Mar 22, 2026

No findings