Skip to content

mahozad/vlc-setup

Repository files navigation

Gradle plugin badge

VLC Setup

A Gradle plugin for Compose Multiplatform desktop applications to automatically embed VLC which is needed to play media files (video, audio, image) via vlcj.

The plugin prepares and includes proper VLC plugin files (.dll for Windows, .so for Linux, .dylib for macOS) so your application becomes self-contained and there will be no need for VLC media player to have been installed on end-user systems.

The plugin features:

  • Support for Windows, Linux, macOS (experimental)
  • Option to compress VLC plugin files to reduce their size
  • Option to include only some base VLC files for common media types
  • Option to select version of VLC to use (not supported for Linux yet)

Warning

The plugin was tested only on my system. Further testing is needed to detect problems.

Note

See the table in supported-formats-codecs.html for supported formats/codecs by the base (default) VLC plugins.

Note

If all VLC plugins are included, then virtually any format and codec should be supported and be playable.

Note

Media player implemented using this plugin worked OK on the OSes defined in tested-operating-systems.html.

Getting started

Follow the steps below to implement a media player in your desktop CMP app.
To see a fully-working real application, visit the Cutcon project.

  1. First, add the plugin to your build.gradle[.kts] file:
    plugins {
        // ...
        id("ir.mahozad.vlc-setup") version "0.1.0"
    }
  2. Next, you should add files to your packaged CMP application.
    So, in build.gradle[.kts] file, specify a custom directory where you would like to place VLC plugin files:
    compose.desktop {
        application {
            // ...
            nativeDistributions {
                appResourcesRootDir = rootDir.resolve("myAssets/") // <projectRoot>/myAssets/
  3. Then specify the plugin options in the vlcSetup{} block in the build.gradle[.kts] file
    (specifically, the same path above suffixed with /<OS name> for each OS where VLC files should be placed):
    vlcSetup {
        vlcVersion = "3.0.21"
        shouldCompressVlcFiles = true
        shouldIncludeAllVlcFiles = false
        pathToCopyVlcLinuxFilesTo = rootDir.resolve("myAssets/linux/")
        pathToCopyVlcMacosFilesTo = rootDir.resolve("myAssets/macos/")
        pathToCopyVlcWindowsFilesTo = rootDir.resolve("myAssets/windows/")
    }
  4. Implement custom vlcj NativeDiscoveryStrategy classes.
    See DefaultVlcDiscoverer and MacOsVlcDiscoverer classes
  5. Implement your media player.
    See MediaPlayer class as an example implementation
  6. Make sure to add --add-opens=java.base/java.nio=ALL-UNNAMED JVM option to start your app.
    See compose.desktop.application{} block in build.gradle.kts

If this repository gets enough attention, another library can be created to make steps 4 and 5 easier.