### Install @clappr/plugins and @clappr/core Source: https://context7.com/clappr/clappr-plugins/llms.txt Install the necessary packages using npm or yarn. ```bash npm install @clappr/plugins @clappr/core # or yarn add @clappr/plugins @clappr/core ``` -------------------------------- ### Initialize Player with All Clappr Plugins Source: https://context7.com/clappr/clappr-plugins/llms.txt Use this snippet to initialize a Clappr player with the complete set of available plugins. Ensure you have `@clappr/core` and `@clappr/plugins` installed. ```javascript import Clappr from '@clappr/core' import { Plugins, version } from '@clappr/plugins' console.log('clappr-plugins version:', version) const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', width: 640, height: 360, plugins: Object.values(Plugins), // MediaControl mediacontrol: { seekbar: '#3DC8E7', buttons: '#FFFFFF' }, persistConfig: true, // Poster poster: 'https://example.com/thumb.jpg', // Watermark watermark: 'https://example.com/logo.png', position: 'top-right', watermarkLink: 'https://example.com', // Google Analytics gaAccount: 'UA-XXXXXXX-1', // Stats reporting every 10 seconds reportInterval: 10000, // DVR seek time tooltip with wall clock actualLiveTime: false, // Favicon changeFavicon: true, // Exit fullscreen on video end exitFullscreenOnEnd: true, }) player.on(Clappr.Events.CONTAINER_STATS_REPORT, (metrics) => { console.log('QoE metrics:', metrics) }) ``` -------------------------------- ### Display Poster Image Source: https://github.com/clappr/clappr-plugins/blob/master/README.md Configure a poster image that appears before playback starts and returns when the video is stopped. For audio, it remains visible during playback. ```javascript var player = new Clappr.Player({ source: "http://your.video/here.mp4", poster: "http://url/img.png" }); ``` -------------------------------- ### Importing Plugins Source: https://context7.com/clappr/clappr-plugins/llms.txt Demonstrates how to import all Clappr plugins as a bundle or individually, and how to register them with a Clappr player. ```APIDOC ## Importing Plugins All plugins can be imported individually or as a single bundle. ```js // Import all plugins as a bundle import { Plugins } from '@clappr/plugins' // Import individually import { MediaControl, ClickToPause, ClosedCaptions, DVRControls, EndVideo, ErrorScreen, Favicon, GoogleAnalytics, Poster, SeekTime, SpinnerThreeBounce, Stats, WaterMark, } from '@clappr/plugins' // Register all built-in plugins with a Clappr player const player = new Clappr.Player({ source: 'https://example.com/video.mp4', plugins: Object.values(Plugins), parentId: '#player', }) ``` ``` -------------------------------- ### Initialize and Attach Clappr Player Source: https://github.com/clappr/clappr-plugins/blob/master/public/index.html Use this snippet to create a new Clappr player instance, specify video source, poster, player dimensions, and attach it to a designated HTML element. External plugins can also be included in the configuration. ```javascript var playerElement = document.getElementById("player-wrapper"); var player = new Clappr.Player({ source: 'http://clappr.io/highline.mp4', poster: 'http://clappr.io/poster.png', mute: true, height: 360, width: 640, plugins: plugins, }); player.attachTo(playerElement); ``` -------------------------------- ### Main Render Function (JavaScript) Source: https://github.com/clappr/clappr-plugins/blob/master/src/plugins/media_control/public/media-control.html Orchestrates the rendering of various media control elements based on a list of settings. It maps settings to specific rendering functions like bars, drawers, indicators, and buttons. ```javascript <% var templates = { bar: renderBar, segmentedBar: renderSegmentedBar, }; var render = function(settingsList) { settingsList.forEach(function(setting) { if(setting === "seekbar") { renderBar(setting); } else if (setting === "volume") { renderDrawer(setting, settings.volumeBarTemplate ? templates[settings.volumeBarTemplate] : function(name) { return renderSegmentedBar(name); }); } else if (setting === "duration" || setting === "position") { renderIndicator(setting); } else { renderButton(setting); } }); }; %> ``` -------------------------------- ### Configure Poster Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt The Poster plugin displays a thumbnail before playback. Configure 'poster' with a URL or an object for advanced options like 'showOnVideoEnd'. ```javascript import { Poster } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [Poster], // Simple string URL poster: 'https://example.com/thumbnail.jpg', // OR object form for advanced control poster: { url: 'https://example.com/thumbnail.jpg', // Show poster again after video ends (default: true) showOnVideoEnd: true, // Show poster even when playback type is NO_OP showForNoOp: false, // Use a CSS value instead of an image (e.g. gradient) // custom: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', }, }) ``` -------------------------------- ### Integrate DVRControls Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt Use DVRControls for live streams with DVR to display a 'LIVE' badge and 'Back to Live' button. Set 'useDvrControls: true' to enable. ```javascript import { DVRControls } from '@clappr/plugins' const player = new Clappr.Player({ // HLS live stream with DVR source: 'https://example.com/stream.m3u8', parentId: '#player', plugins: [DVRControls], // Set to false to hide DVR controls even on live streams useDvrControls: true, }) // The plugin automatically shows/hides based on playback type. // When the user is behind the live edge the media control gains // the CSS class "dvr"; clicking the LIVE button seeks to the end. ``` -------------------------------- ### Import and Register Clappr Plugins Source: https://context7.com/clappr/clappr-plugins/llms.txt Import plugins individually or as a bundle. Register all built-in plugins with a Clappr player instance. ```javascript // Import all plugins as a bundle import { Plugins } from '@clappr/plugins' // Import individually import { MediaControl, ClickToPause, ClosedCaptions, DVRControls, EndVideo, ErrorScreen, Favicon, GoogleAnalytics, Poster, SeekTime, SpinnerThreeBounce, Stats, WaterMark, } from '@clappr/plugins' // Register all built-in plugins with a Clappr player const player = new Clappr.Player({ source: 'https://example.com/video.mp4', plugins: Object.values(Plugins), parentId: '#player', }) ``` -------------------------------- ### Configure SeekTime Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt SeekTime shows a time tooltip on hover. For live DVR streams, set 'actualLiveTime: true' to display wall-clock time. Optionally provide 'actualLiveServerTime'. ```javascript import { SeekTime } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/stream.m3u8', parentId: '#player', plugins: [SeekTime], // Show wall-clock time instead of DVR offset on live+DVR streams actualLiveTime: true, // Reference server time to align wall-clock display // If omitted, the browser's local clock is used actualLiveServerTime: '2024-06-15 14:30:00', }) // On VOD or DVR streams, hovering the seek bar displays // a tooltip like "1:23" (offset) or "14:31" (wall clock). ``` -------------------------------- ### Configure Live Seek Time Source: https://github.com/clappr/clappr-plugins/blob/master/README.md Enable displaying the current time on hover for the seekbar, specifically for live streams with DVR. Requires `actualLiveTime` to be true and `actualLiveServerTime` to be set. ```javascript var player = new Clappr.Player({ source: "http://your.video/here.mp4", // Only for live stream with DVR actualLiveTime: true, // default is false // Meant to be used with actualLiveTime actualLiveServerTime: "2015/11/26 06:01:03" // default is current date }); ``` -------------------------------- ### Configure and Use Stats Plugin for QoE Metrics Source: https://context7.com/clappr/clappr-plugins/llms.txt Enables the Stats Container plugin to collect and report Quality-of-Experience metrics. Listen for 'CONTAINER_STATS_REPORT' events to receive metrics. External metrics can be added via 'CONTAINER_STATS_ADD' or 'CONTAINER_BITRATE'. ```javascript import { Stats } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [Stats], // How often to emit stats reports (ms), default: 5000 reportInterval: 10000, }) // Listen for stats reports on the container player.on(Clappr.Events.CONTAINER_STATS_REPORT, (metrics) => { console.log(metrics) // { // startupTime: 450, // ms from first buffer to playback start // rebuffers: 2, // total rebuffer events // rebufferingTime: 1200, // total ms spent rebuffering // watchingTime: 30000, // ms of actual watching (excluding rebuffers) // // any extra metrics added via CONTAINER_STATS_ADD or CONTAINER_BITRATE // } }) // External metrics can be merged in from playback plugins via: // container.trigger(Events.CONTAINER_STATS_ADD, { bitrate: 3500000 }) // container.trigger(Events.CONTAINER_BITRATE, { bitrate: 3500000 }) ``` -------------------------------- ### ClickToPause Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt Explains the ClickToPause plugin, which allows users to toggle play/pause by clicking the video container, and its configuration for optional payloads. ```APIDOC ## ClickToPause `ClickToPause` is a `ContainerPlugin` that toggles play/pause when the user clicks on the video container. It is disabled automatically for live streams without DVR, and can forward an optional payload to the container on click. ```js import { ClickToPause } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [ClickToPause], clickToPauseConfig: { // Optional payload forwarded to container.pause() / container.play() onClickPayload: { origin: 'user-click' }, }, }) ``` ``` -------------------------------- ### Configure WaterMark Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt Adds a watermark image to the video player. Configure the watermark image URL, position, and an optional click-to-navigate link. ```javascript import { WaterMark } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [WaterMark], // URL of the watermark image watermark: 'https://example.com/logo.png', // Corner position: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right' position: 'top-right', // Optional: URL to navigate to when watermark is clicked watermarkLink: 'https://example.com', }) ``` -------------------------------- ### Configure ClickToPause Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt Enable the ClickToPause plugin to toggle play/pause on video container click. Configure an optional payload to be forwarded to the container's play/pause methods. ```javascript import { ClickToPause } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [ClickToPause], clickToPauseConfig: { // Optional payload forwarded to container.pause() / container.play() onClickPayload: { origin: 'user-click' }, }, }) ``` -------------------------------- ### Configure Click to Pause Plugin Source: https://github.com/clappr/clappr-plugins/blob/master/README.md Configure the clickToPause plugin to toggle play/pause by clicking the container. Optionally, send a payload with the `onClickPayload` parameter when the container is clicked. ```javascript var player = new Clappr.Player({ source: "http://your.video/here.mp4", // Optionally, send a payload upon the container's pausing with the `onClickPayload` parameter clickToPauseConfig: { onClickPayload: { any: 'any' } // sends the payload to container when clicked }); ``` -------------------------------- ### Configure EndVideo Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt Integrates the EndVideo Core plugin to automatically exit fullscreen mode when playback ends or the player stops. The default behavior is enabled, but can be disabled by setting `exitFullscreenOnEnd` to `false`. ```javascript import { EndVideo } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [EndVideo], // Set to false to stay in fullscreen when video ends exitFullscreenOnEnd: true, }) ``` -------------------------------- ### Integrate ErrorScreen Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt Implement ErrorScreen to show a full-screen error overlay for fatal playback errors. Configure 'disableErrorScreen: false' to enable. ```javascript import { ErrorScreen } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [ErrorScreen], // Set to true to suppress the error screen entirely disableErrorScreen: false, }) // The plugin listens to Events.ERROR on the core. // Only errors with level === PlayerError.Levels.FATAL trigger the overlay. // On reload, the plugin calls core.load(sources, mimeType) then container.play(). ``` -------------------------------- ### Configure and Use MediaControl Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt Configure the MediaControl plugin for the player's control bar, including customization of colors, behavior, and UI elements. Programmatically control volume, mute, fullscreen, and visibility. ```javascript import { MediaControl } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [MediaControl], // Customize control bar layout // left / right / default sections accept button names mediacontrol: { seekbar: '#E6461E', // seekbar fill color buttons: '#FFFFFF', // icon color }, // Persist volume across page loads persistConfig: true, // Start muted mute: true, // Hide the control bar permanently (chromeless mode) chromeless: false, // Delay before auto-hiding controls (ms), default 2000 hideMediaControlDelay: 3000, // Disable keyboard shortcuts (space, arrow keys, 0-9) disableKeyboardShortcuts: false, // Hide volume bar on small players hideVolumeBar: false, }) // Programmatic volume control via the external interface const mediaControl = player.core.getPlugin('media_control') mediaControl.setVolume(75) // set volume 0-100 mediaControl.toggleMute() // toggle mute mediaControl.toggleFullscreen() // toggle fullscreen mediaControl.show() // force show controls mediaControl.hide() // force hide controls mediaControl.disable() // hide and lock controls mediaControl.enable() // restore controls ``` -------------------------------- ### Integrate GoogleAnalytics Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt Use GoogleAnalytics to push video events to GA. Requires 'gaAccount' (UA tracking ID) and optionally 'gaTrackerName' and 'gaDomainName'. ```javascript import { GoogleAnalytics } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [GoogleAnalytics], // Required: your UA tracking ID gaAccount: 'UA-XXXXXXX-1', // Optional: custom tracker name prefix (default: 'Clappr') gaTrackerName: 'MyPlayer', // Optional: domain name for cross-domain tracking gaDomainName: 'example.com', }) // Events pushed to GA (category / action / label): // Video / Playback / // Video / Play / // Video / Pause / // Video / Stop / // Video / Ended / // Video / Buffering / // Video / Bufferfull / // Video / Error / // Video / HD - ON|OFF / // Video / Playback Type - / // Interaction / Volume / // Interaction / Fullscreen / // Interaction / DVR - ON|OFF / ``` -------------------------------- ### Render Drawer Function (JavaScript) Source: https://github.com/clappr/clappr-plugins/blob/master/src/plugins/media_control/public/media-control.html Defines a JavaScript function to render a drawer component, which can contain custom content. It accepts a renderContent callback to populate the drawer. ```javascript <% var renderDrawer = function(name, renderContent) { %> > > > > <% renderContent(name); %> <% }; %> ``` -------------------------------- ### MediaControl Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt Details the MediaControl plugin, its configuration options for customizing the control bar, and programmatic control methods. ```APIDOC ## MediaControl `MediaControl` is the primary UI overlay plugin (extends `UICorePlugin`) that renders the player's control bar, including play/pause/stop buttons, a seek bar, volume controls, fullscreen toggle, and HD indicator. It handles keyboard shortcuts, drag interactions on the seek and volume bars, and auto-hides after inactivity. ```js import { MediaControl } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [MediaControl], // Customize control bar layout // left / right / default sections accept button names mediacontrol: { seekbar: '#E6461E', // seekbar fill color buttons: '#FFFFFF', // icon color }, // Persist volume across page loads persistConfig: true, // Start muted mute: true, // Hide the control bar permanently (chromeless mode) chromeless: false, // Delay before auto-hiding controls (ms), default 2000 hideMediaControlDelay: 3000, // Disable keyboard shortcuts (space, arrow keys, 0-9) disableKeyboardShortcuts: false, // Hide volume bar on small players hideVolumeBar: false, }) // Programmatic volume control via the external interface const mediaControl = player.core.getPlugin('media_control') mediaControl.setVolume(75) // set volume 0-100 mediaControl.toggleMute() // toggle mute mediaControl.toggleFullscreen() // toggle fullscreen mediaControl.show() // force show controls mediaControl.hide() // force hide controls mediaControl.disable() // hide and lock controls mediaControl.enable() // restore controls ``` ``` -------------------------------- ### Enable Google Analytics Events Source: https://github.com/clappr/clappr-plugins/blob/master/README.md Add your Google Analytics account ID to dispatch play/pause/stop/buffering events. Optionally, specify a tracker name. ```javascript var player = new Clappr.Player({ source: "http://your.video/here.mp4", gaAccount: 'UA-44332211-1', gaTrackerName: 'MyPlayerInstance' }); ``` -------------------------------- ### Configure ClosedCaptions Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt Add a CC button to the media control bar using the ClosedCaptions plugin. Configure the button's label, aria label, and customize track display names via a callback function. ```javascript import { ClosedCaptions } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [ClosedCaptions], closedCaptionsConfig: { // Title shown above the track list dropdown title: 'Subtitles', // Accessible aria-label for the CC button ariaLabel: 'Closed Captions', // Custom function to derive the label shown per track // track: { id, name, track } — track.track is the native TextTrack object labelCallback: (track) => track.name.toUpperCase(), }, }) ``` -------------------------------- ### Add SpinnerThreeBounce Plugin to Clappr Player Source: https://context7.com/clappr/clappr-plugins/llms.txt Integrates the SpinnerThreeBounce UI plugin to display a buffering indicator. No configuration is needed as it's fully automatic. ```javascript import { SpinnerThreeBounce } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [SpinnerThreeBounce], // No configuration options — the plugin is fully automatic. }) ``` -------------------------------- ### Enable Favicon Plugin for Playback State Indication Source: https://context7.com/clappr/clappr-plugins/llms.txt Activates the Favicon Core plugin to dynamically change the browser tab favicon based on playback state (playing, paused, stopped, error). Must be explicitly enabled with `changeFavicon: true`. ```javascript import { Favicon } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [Favicon], // Must be true to activate favicon changes changeFavicon: true, }) // State → favicon mapping: // CONTAINER_PLAY → play triangle icon (SVG rendered to 16×16 canvas) // CONTAINER_PAUSE → pause bars icon // CONTAINER_STOP → restored to original page favicon // CONTAINER_ENDED → restored to original page favicon // CONTAINER_ERROR → restored to original page favicon ``` -------------------------------- ### Conditional Rendering of Media Controls (HTML/JavaScript) Source: https://github.com/clappr/clappr-plugins/blob/master/src/plugins/media_control/public/media-control.html Renders media control elements based on the presence and content of 'default', 'left', and 'right' settings arrays. Uses the main 'render' function to process each section. ```html <% if (settings.default && settings.default.length) { %> <% render(settings.default); %> <% } %> <% if (settings.left && settings.left.length) { %> <% render(settings.left); %> <% } %> <% if (settings.right && settings.right.length) { %> <% render(settings.right); %> <% } %> ``` -------------------------------- ### Control Fullscreen Exit on End Source: https://github.com/clappr/clappr-plugins/blob/master/README.md Configure whether the player should exit fullscreen mode automatically when the video finishes. Set `exitFullscreenOnEnd` to `false` to disable this behavior. ```javascript var player = new Clappr.Player({ source: "http://your.video/here.mp4", exitFullscreenOnEnd: false }); ``` -------------------------------- ### Add Clickable Watermark Source: https://github.com/clappr/clappr-plugins/blob/master/README.md Embed a watermark image over the video. Specify its position (e.g., 'top-right') and an optional URL to open when clicked. If `watermarkLink` is omitted, the watermark is not clickable. ```javascript var player = new Clappr.Player({ source: "http://your.video/here.mp4", watermark: "http://url/img.png", position: 'top-right', watermarkLink: "http://example.net/" }); ``` -------------------------------- ### Render Segmented Bar Function (JavaScript) Source: https://github.com/clappr/clappr-plugins/blob/master/src/plugins/media_control/public/media-control.html Defines a JavaScript function to render a segmented bar, allowing for a visual representation divided into segments. Defaults to 10 segments if not specified. ```javascript <% var renderSegmentedBar = function(name, segments) { segments = segments || 10; %> > <% for (var i = 0; i < segments; i++) { %> > <% } %> <% }; %> ``` -------------------------------- ### Render Bar Function (JavaScript) Source: https://github.com/clappr/clappr-plugins/blob/master/src/plugins/media_control/public/media-control.html Defines a JavaScript function to render a simple bar element. Used for basic visual representation. ```javascript <% var renderBar = function(name) { %> > > > > > > > <% }; %> ``` -------------------------------- ### ClosedCaptions Plugin Source: https://context7.com/clappr/clappr-plugins/llms.txt Details the ClosedCaptions plugin, which adds a CC button to the control bar for selecting subtitle tracks, and its configuration options for customization. ```APIDOC ## ClosedCaptions `ClosedCaptions` is a `UICorePlugin` that adds a CC button to the media control bar. When subtitle tracks are available, it renders a dropdown menu allowing the viewer to select or disable tracks. The button label, aria label, and track display names are all configurable. ```js import { ClosedCaptions } from '@clappr/plugins' const player = new Clappr.Player({ source: 'https://example.com/video.mp4', parentId: '#player', plugins: [ClosedCaptions], closedCaptionsConfig: { // Title shown above the track list dropdown title: 'Subtitles', // Accessible aria-label for the CC button ariaLabel: 'Closed Captions', // Custom function to derive the label shown per track // track: { id, name, track } — track.track is the native TextTrack object labelCallback: (track) => track.name.toUpperCase(), }, }) ``` ``` -------------------------------- ### Configure Closed Captions Plugin Source: https://github.com/clappr/clappr-plugins/blob/master/README.md Customize the label and title for the closed captions button. The `labelCallback` function can be used to dynamically set the track label. ```javascript var player = new Clappr.Player({ source: "http://your.video/here.mp4", closedCaptionsConfig: { title: 'Subtitles', // default is none ariaLabel: 'Closed Captions', // Default is 'cc-button' labelCallback: function (track) { return track.name }, // track is an object with id, name and track properties (track is TextTrack object) }, }); ``` -------------------------------- ### Render Indicator Function (JavaScript) Source: https://github.com/clappr/clappr-plugins/blob/master/src/plugins/media_control/public/media-control.html Defines a JavaScript function to render an indicator element. Typically used for status or time displays. ```javascript <% var renderIndicator = function(name) { %> > <% }; %> ``` -------------------------------- ### Render Button Function (JavaScript) Source: https://github.com/clappr/clappr-plugins/blob/master/src/plugins/media_control/public/media-control.html Defines a JavaScript function to render a button element with an aria-label attribute. ```javascript <% var renderButton = function(name) { %> aria-label="<%= name %>"> <% }; %> ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.