# `` component for easy video integration. `` is a Svelte component specially designed to work seamlessly with DatoCMS’s [`video` GraphQL query](https://www.datocms.com/docs/content-delivery-api/images-and-videos#videos) that optimizes video streaming for your sites. To stream videos, DatoCMS partners with MUX, a video CDN that serves optimized streams to your users. Our component is a wrapper around [MUX's video player](https://github.com/muxinc/elements/blob/main/packages/mux-player/README.md) [web component](https://developer.mozilla.org/en-US/docs/Web/API/Web_components). It takes care of the details for you, and this is our recommended way to serve optimal videos to your users. ## Out-of-the-box features - Offers optimized streaming so smartphones and tablets don’t request desktop-sized videos - Lazy loads the underlying video player web component and the video to be played to speed initial page load and save bandwidth - Holds the video position so your page doesn’t jump while the player loads - Uses blur-up technique to show a placeholder of the video while it loads ### Table of contents - [Installation](#installation) - [Usage](#usage) - [Example](#example) - [Props](#props) - [Opt-in Viewer Analytics](#opt-in-viewer-analytics) ## Installation ```sh {"id":"01HP46D8MDP5Y76HY788MWNDMX"} npm install --save @datocms/svelte @mux/mux-player ``` `@mux/mux-player` is a [peer dependency](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependencies) for `@datocms/svelte`: so you're expected to add it to your project. ## Usage 1. Import `VideoPlayer` from `@datocms/svelte` and use it in your app 2. Write a GraphQL query to your DatoCMS project using the [`video` query](https://www.datocms.com/docs/content-delivery-api/images-and-videos#videos) The GraphQL query returns data that the `VideoPlayer` component automatically uses to properly size the player, set up a “blur-up” placeholder as well as lazy loading the video. ## Example ```svelte {"id":"01HP46D8MDP5Y76HY78BNPWHB2"}
{#if data}

{{ data.blogPost.title }}

{/if}
``` ## Props The `` component supports as props all the [attributes](https://github.com/muxinc/elements/blob/main/packages/mux-player/REFERENCE.md) of the `` web component, plus `data`, which is meant to receive data directly in the shape they are provided by DatoCMS GraphQL API. `` uses the `data` prop to generate a set of attributes for the inner ``. | prop | type | required | description | default | | ------ | -------------- | ------------------ | ---------------------------------------------------------------- | ------- | | data | `Video` object | :white_check_mark: | The actual response you get from a DatoCMS `video` GraphQL query | | | paused | `boolean` | | Control to play or pause the video | | `` generate some default attributes: - when not declared, the `disableCookies` prop is true, unless you explicitly set the prop to `false` (therefore it generates a `disable-cookies` attribute) - when not declared, the `disableTracking` prop is true, unelss you explicitly set it to `false` (so, it normally generates a `disable-tracking` attribute) - `preload` defaults to `metadata`, for an optimal UX experience together with saved bandwidth - the video height and width, when available in the `data` props, are used to set a default `aspect-ratio: [width] / [height];` for the ``'s `style` attribute All the other props are forwarded to the `` web component that is used internally. ## Opt-in Viewer Analytics This `` component can OPTIONALLY collect clientside [playback and engagement metrics](https://www.mux.com/data#TechSpecs) such as playback percentages, user agents, and geography. These analytics are **disabled** by default. To enable them, you must opt in to [Mux Data](https://www.mux.com/data) integration by creating a Mux Data account (free) and providing its `envKey` to the component. For details and setup instructions, please see our documentation on **[Streaming Video Analytics with Mux Data](https://www.datocms.com/docs/streaming-videos/streaming-video-analytics-with-mux-data)**.