--- url: "https://web.dev/articles/eme-basics" titulek: "Introduction to Encrypted Media Extensions | Articles | web.dev" h1: "Introduction to Encrypted Media Extensions Stay organized with collections Save and categorize content based on your preferences." popis: "" jazyk: "en" kanonicka: "https://web.dev/articles/eme-basics" drobecky: ["Articles", "Introduction to Encrypted Media Extensions"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 23:11:05" znaku: 20639 slov: 2734 kodovani: "iso-8859-2" sha256: "ab81a45eb15bb2a3b15c636db5eece55eacfdf42eb462f3fd2ec59f684b6d2cf" --- Introduction to Encrypted Media Extensions Stay organized with collections Save and categorize content based on your preferences. Sam Dutton Encrypted Media Extensions (EME) provides an API that enables web applications to interact with content protection systems, to allow playback of encrypted audio and video. EME is designed to enable the same app and encrypted files to be used in any browser, regardless of the underlying protection system. The former is made possible by the standardized APIs and flow while the latter is made possible by the concept of Common Encryption. EME is an extension to the `HTMLMediaElement` specification - hence the name. Being an 'extension' means that browser support for EME is optional: if a browser does not support encrypted media, it won't be able to play encrypted media, but EME is not required for HTML spec compliance. From [the EME spec](https://w3c.github.io/encrypted-media/): EME implementations use the following external components: **Key System:** A content protection (DRM) mechanism. EME doesn't define Key Systems themselves, apart from Clear Key (more about that below). **Content Decryption Module (CDM):** A client-side software or hardware mechanism that enables playback of encrypted media. As with Key Systems, EME doesn't define any CDMs, but provides an interface for applications to interact with CDMs that are available. **License (Key) server:** Interacts with a CDM to provide keys to decrypt media. Negotiation with the license server is the responsibility of the application. **Packaging service:** Encodes and encrypts media for distribution/consumption. Note that an application using EME interacts with a license server to get keys to enable decryption, but user identity and authentication are not part of EME. Retrieval of keys to enable media playback happens after (optionally) authenticating a user. Services such as Netflix must authenticate users within their web application: when a user signs into the application, the application determines the user's identity and privileges. How does EME work? Here's how the components of EME interact, corresponding to the following code example: A web application attempts to play audio or video that has one or more encrypted streams. The browser recognizes that the media is encrypted (see box below for how that happens) and fires an `encrypted` event with metadata (`initData`) obtained from the media about the encryption. The application handles the `encrypted` event: If no `MediaKeys` object has been associated with the media element, first select an available Key System by using [`navigator.requestMediaKeySystemAccess()`](https://w3c.github.io/encrypted-media/#navigator-extension-requestmediakeysystemaccess) to check what Key Systems are available, then create a `MediaKeys` object for an available Key System via a `MediaKeySystemAccess` object. Note that initialization of the MediaKeys object should happen before the first `encrypted` event. Getting a license server URL is done by the app independently of selecting an available key system. A `MediaKeys` object represents all the keys available to decrypt the media for an audio or video element. It represents a CDM instance and provides access to the CDM, specifically for creating key sessions, which are used to obtain keys from a license server. Once the `MediaKeys` object has been created, assign it to the media element: [`setMediaKeys()`](https://w3c.github.io/encrypted-media/#widl-HTMLMediaElement-setMediaKeys-Promise-void--MediaKeys-mediaKeys) associates the `MediaKeys` object with an HTMLMediaElement, so that its keys can be used during playback, i.e. during decoding. The app creates a `MediaKeySession` by calling `createSession()` on the `MediaKeys`. This creates a `MediaKeySession`, which represents the lifetime of a license and its key(s). The app generates a license request by passing the media data obtained in the `encrypted` handler to the CDM, by calling `generateRequest()` on the `MediaKeySession`. The CDM fires a `message` event: a request to acquire a key from a license server. The `MediaKeySession` object receives the `message` event and the application sends a message to the license server (via XHR, for example). The application receives a response from the license server and passes the data to the CDM using the `update()` method of the `MediaKeySession`. The CDM decrypts the media using the keys in the license. A valid key may be used, from any session within the `MediaKey`s associated with the media element. The CDM will access the key and policy, indexed by Key ID. Media playback resumes. Phew… Note that there may be multiple messages between the CDM and the license server, and all communication in this process is opaque to the browser and application: messages are only understood by the CDM and license server, although the app layer can see [what type of message](//w3c.github.io/encrypted-media/#idl-def-MediaKeyMessageType) the CDM is sending. The license request contains proof of the CDM's validity (and trust relationship) as well as a key to use when encrypting the content key(s) in the resulting license. …but what do CDMs actually do? An EME implementation does not in itself provide a way to decrypt media: it simply provides an API for a web application to interact with Content Decryption Modules. What CDMs actually do is not defined by the EME spec, and a CDM may handle decoding (decompression) of media as well as decryption. From least to most robust, there are several potential options for CDM functionality: Decryption only, enabling playback using the normal media pipeline, for example via a `