Vidstack Player
repository·main·Indexed 25 days ago
https://github.com/vidstack/playerA robust, customizable, and accessible media player library for video and audio. Designed as a modern successor to Plyr and Vime, it supports multiple JavaScript frameworks and web components. It provides tools for building high-quality media experiences, including pre-built layouts (such as Plyr-based designs), customizable slot-based UI systems, and components for managing text tracks and media providers.
What's inside Vidstack Player
- Vidstack is a video and audio platform designed for frontend developers to build high-quality, accessible media experiences on the web.
Get started with Vidstack React
mainVidstack is a video and audio platform designed for frontend developers to build high-quality, accessible media experiences on the web. For comprehensive documentation, API references, and guides, visit the official documentation website at vidstack.io.Quickstart with Vidstack Player
mainVidstack Player is a production-ready, customizable, and accessible video or audio player. It is designed to work with various JavaScript frameworks. You can either build your own custom player layout using provided components or use pre-built layouts for rapid development.
To get started, choose the installation guide corresponding to your framework or environment:
Access Vidstack Documentation
mainComprehensive documentation for using Vidstack, including guides and API references, can be found at vidstack.io.Understand Vidstack bundle types
mainVidstack produces several distinct types of bundles depending on the target environment and distribution method:
NPM Bundles
Distributed via npm, these are categorized by environment:
- server: Optimized for server-side environments (e.g., Node.js). Element entry points are transformed into no-ops to prevent server-side errors.
- dev: Development builds with
__DEV__: true. - prod: Production builds with
__DEV__: falseand minification.
CDN Bundles
Optimized for direct browser usage via JSDelivr. These bundles use specific external paths for dependencies like
media-iconsandmedia-captionsto reduce bundle size.Plugins Bundle
A dedicated bundle for Vidstack plugins, optimized for Node.js environments.
Types Bundles
Provides TypeScript definitions for the core library, elements, global player interfaces, and icons.
Use the Cast Application Framework (CAF)
mainThe
cast.frameworkprovides a higher-level abstraction for managing Cast state and sessions.Configure CastContext
Use
cast.framework.CastContext.getInstance()to access the singleton context. You can configure it usingsetOptions(options)whereCastOptionsincludes:autoJoinPolicy:chrome.cast.AutoJoinPolicylanguage: Optional stringreceiverApplicationId: Optional stringresumeSavedSession: Optional booleanandroidReceiverCompatible: Optional boolean (enables Cast Connect for Chrome 87+)
Listen for Cast Events
Use
CastContext.addEventListenerto listen for:cast.framework.CastContextEventType.CAST_STATE_CHANGED: Detects if devices are available or if the user is connected.cast.framework.CastContextEventType.SESSION_STATE_CHANGED: Detects changes in the session lifecycle (e.g.,SESSION_STARTED,SESSION_ENDED).
Manage CastSession
cast.framework.CastSessionprovides a Promise-based API for common tasks:requestSession(): Returns a Promise resolving to an error code or undefined.setVolume(volume): Returns a Promise.setMute(mute): Returns a Promise.sendMessage(namespace, data): Returns a Promise.loadMedia(request): Returns a Promise.
Use the Menu component in React
mainThe
Menucomponent provides a set of primitives to build floating menus, submenus, and option lists. It consists of aRootcontainer, aButtonto trigger the menu, andItems(orContent) to holdItemcomponents.Basic usage pattern:
<Menu.Root> <Menu.Button>Open Menu</Menu.Button> <Menu.Content placement="top end"> <Menu.Item>Option 1</Menu.Item> <Menu.Item>Option 2</Menu.Item> </Menu.Content> </Menu.Root><Menu.Root> <Menu.Button></Menu.Button> <Menu.Content placement="top end"></Menu.Content> </Menu.Root>Build Vidstack using tsdown CLI flags
mainThe Vidstack build process can be customized using specific command-line flags when running the build script. These flags control which bundles are generated:
--types: Generates TypeScript definition bundles (.d.tsfiles).--cdn: Generates CDN-optimized bundles.--plugins: Generates the plugins bundle.--css: (Currently returns an empty config, effectively skipping standard bundles).-wor--watch: Enables watch mode. When used with--types, it also triggerswatchStyles()to monitor CSS changes.
Use the Plyr layout bundle
mainThe Plyr layout bundle provides a collection of pre-defined custom elements that form the Plyr-inspired player layout. When this bundle is imported, it registers several media components as custom elements, including the main layout, buttons, sliders, menus, and display elements. The primary entry point for the layout isMediaPlyrLayoutElement.Configure quality switching with VideoQualityList.switch
mainThe
VideoQualityListclass allows you to control how quality level switches are executed using theswitchproperty. You can choose between three modes:current: Triggers an immediate switch. This aborts the current fragment request, flushes the buffer, and fetches the new quality level matching the current position.next: Triggers a switch for the next fragment. This may eventually flush already buffered next fragments.load: Sets the quality level for the next loaded fragment.
Defaults to
'current'.Configure the @vidstack/react build with tsdown
mainThe
@vidstack/reactpackage usestsdownfor its build process, generating different bundles forserver,dev, andprodenvironments.Bundle Types
- server: Optimized for server-side environments (e.g., Node.js), using
platform: 'neutral'. - dev: Optimized for development, including
__DEV__: trueand specific module resolution conditions. - prod: Optimized for production, including
__DEV__: false, minification-ready settings, and the inclusion ofvidstack-icons.
External Dependencies
The following packages are treated as external and are never bundled into the Vidstack output:
reactreact-dommedia-iconsmedia-captionshls.jsdashjs@floating-ui/*remotion/*
Entry Points
The build generates several sub-path exports for the player, including:
vidstack: The main entry point.player/vidstack-remotion: Remotion provider.player/vidstack-default-layout: Default layout components.player/vidstack-plyr-layout: Plyr layout components.player/vidstack-plyr-icons: Plyr specific icons.player/vidstack-default-components: Default UI components.player/vidstack-default-icons: Default icons.
- server: Optimized for server-side environments (e.g., Node.js), using
Configure the Plyr instance
mainWhen initializing
Plyrvianew Plyr(target, config)orPlyr.setup(targets, config), you can provide aPlyrConfigobject to customize behavior.Key configuration options include:
enabled: (boolean) Completely disable Plyr. Defaults totrue.autoPause: (boolean) If true, only one player will play at a time. Defaults totrue.ratio: (string | null) The video aspect ratio (e.g.,'16/9'). Defaults tonull.hideControls: (boolean) Automatically hide controls after inactivity. Defaults totrue.resetOnEnd: (boolean) Reset playback to the start when media ends. Defaults tofalse.disableContextMenu: (boolean) Disable right-click menu on the video. Defaults totrue.iconUrl: (string | null) URL to a custom SVG sprite.keyboard: (object) Configure keyboard shortcuts viafocused(boolean) andglobal(boolean) properties.