[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eThis document explains how to integrate DRM with Google Cast using ExoPlayer's \u003ccode\u003eMediaInfo\u003c/code\u003e for passing DRM configurations to receiver applications.\u003c/p\u003e\n"],["\u003cp\u003eSample code is provided to demonstrate setting up DRM configurations, including headers, license URL, and protection system within your ExoPlayer application.\u003c/p\u003e\n"],["\u003cp\u003eWeb Receiver applications can utilize load request interceptors, license request handlers, and media playback info handlers to handle DRM protected content securely.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code is for illustrative purposes only, and you are strongly advised to consult with your DRM vendor for best practices and to build your own custom receiver application.\u003c/p\u003e\n"],["\u003cp\u003eRefer to ExoPlayer and Google Cast documentation for further information and troubleshooting.\u003c/p\u003e\n"]]],["This document details integrating DRM with ExoPlayer and Google Cast. Key actions include configuring DRM settings (headers, license URL, protection system) within ExoPlayer's `MediaItem`, which are then sent to the receiver as `customData`. The receiver uses a load request interceptor to capture this configuration. Subsequently, a license request handler customizes the HTTPS license request, and a media playback info handler adjusts playback configuration per media item. Finally, The document emphasizes using `licenseRequestHandler` and `mediaPlaybackInfoHandler` for customization.\n"],null,["# ExoPlayer Integration\n\nThis document provides an overview of the queueing and DRM integration\nsupport.\n\nDRM enhancements\n----------------\n\n| **Warning:** The code in this section is provided as an example only. If you require content protection in your receiver application, it is recommended you create a custom receiver and consult with your DRM vendor for best practices on securing your content.\n| **Note:** Web Receivers automatically handle DASH or HLS manifests that contain the DRM license and key URL.\n\nThe [ExoPlayer Cast Demo](https://github.com/google/ExoPlayer/tree/release-v2/demos/cast)\nhas been updated to utilize a structured way to pass DRM configuration using\nExoPlayer's `MediaInfo` to a receiver application. The Cast sample\nalso uses a demo receiver that includes the same code in this overview, allowing\nyou to test out DRM support. However, if you would like to Cast DRM protected\ncontent, you should build and host your own\n[Web Receiver](https://developers.google.com/cast/docs/caf_receiver/).\n\nBefore beginning, it would be helpful to familiarize yourself with the\ndocumentation on DRM support in\n[Google Cast](https://developers.google.com/cast/docs/mpl/streaming_protocols#drm)\nand [ExoPlayer](https://exoplayer.dev/drm.html). This overview will show you how\nto wire-up the ExoPlayer DRM configuration to a Web Receiver. For information\non how to utilize DRM in ExoPlayer, see the official\n[ExoPlayer website](https://exoplayer.dev).\n\n### Providing the DRM configuration\n\nThe ExoPlayer demo app contains sample code that shows how to provide DRM\nconfiguration as part of a MediaItem. The four options you can configure are:\n\n- **Headers** - a dictionary of headers that are applied to the HTTPS request to retrieve the DRM license.\n- **License URL** - the URL used to acquire the license.\n- **Protection System** - the DRM protection scheme used to protect the content, for example, Widevine.\n\nThe DRM configuration you provide to ExoPlayer is sent to your receiver\napplication as a property in `customData` on the [`MediaInformation`](https://developers.google.com/cast/docs/reference/caf_receiver/cast.framework.messages.MediaInformation)\nobject as part of a load request. By default, this property is called\n`exoPlayerConfig`, which matches the following definition. \n\n /**\n * Extended configuration settings for ExoPlayer.\n */\n ExoPlayerConfig class {\n constructor() {\n /**\n * Dictionary of headers to apply to the license request.\n * @type {!Object|undefined}\n */\n this.headers;\n\n /**\n * The URL for your DRM server.\n * @type {string|undefined}\n */\n this.licenseUrl;\n\n /**\n * Preferred protection system to use for decrypting content.\n * @type {!cast.framework.ContentProtection|undefined}\n */\n this.protectionSystem;\n\n /**\n * Indicates whether CORS Access-Control requests should be made using\n * credentials such as cookies or authorization headers.\n *\n * If withCredentials is set to true then Access-Control-Allow-Origin cannot\n * be set to '*'.\n * @type {boolean|undefined}\n */\n this.withCredentials;\n }\n }\n\n### Initial setup\n\nDepending on the DRM solution you use, you might need to configure a [`licenseRequestHandler`](https://developers.google.com/cast/docs/reference/caf_receiver/cast.framework.PlaybackConfig#licenseRequestHandler)\nand a [`mediaPlaybackInfoHandler`](https://developers.google.com/cast/docs/reference/caf_receiver/cast.framework.PlayerManager#setMediaPlaybackInfoHandler). The `licenseRequestHandler` allows you to customize\nhow CAF requests a license from your license key server. The\n`mediaPlaybackInfoHandler` lets you modify the\n[`PlaybackConfig`](https://developers.google.com/cast/docs/reference/caf_receiver/cast.framework.PlaybackConfig)\non a per media item basis if, for example, each piece of content has to use a\ndifferent license server URL.\n\nTo capture a copy of the `ExoPlayerConfig` from each load request object, create\na load request interceptor in your Web Receiver SDK application.\n\nThe first step is to register your handlers before starting your Cast\napplication. \n\n const context = cast.framework.CastReceiverContext.getInstance();\n const playbackConfig = new cast.framework.PlaybackConfig();\n\n playbackConfig.licenseRequestHandler =\n licenseRequestHandler;\n context.getPlayerManager().setMediaPlaybackInfoHandler(\n mediaPlaybackInfoHandler);\n context.getPlayerManager().setMessageInterceptor(\n cast.framework.messages.MessageType.LOAD,\n loadInterceptor);\n\n // starts the Cast application\n context.start({playbackConfig: playbackConfig});\n\n### Load request interceptor\n\nThe load request interceptor is a callback that allows you to view and modify a\nCast load request before CAF attempts to load a media item. Importantly, it is\ncalled before the license request hander and the media playback info handler.\n\nThe load request interceptor is passed a [`LoadRequestData`](https://developers.google.com/cast/docs/reference/caf_receiver/cast.framework.messages.LoadRequestData)\nobject that contains the Exo Player Config that was sent by your app. You can\nsave this object as a global variable for use in your license request handler\nand media playback info handler. \n\n loadInterceptor(loadRequestData) {\n // not every load request will have a customData object\n if (loadRequestData.media && loadRequestData.media.customData &&\n loadRequestData.media.customData['exoPlayerConfig']) {\n // exoPlayerConfig is a global variable here\n exoPlayerConfig =\n loadRequestData.media.customData['exoPlayerConfig'];\n }\n\n // you must return the loadRequestData object\n return loadRequestData;\n }\n\n### License request handler\n\nThe license request handler allows you to customize the HTTPS request Web\nReceiver makes to your license server. The handler is passed a [`NetworkRequestInfo`](https://developers.google.com/cast/docs/reference/caf_receiver/cast.framework.NetworkRequestInfo)\nobject, which you can then use to add HTTP headers, include cookies, or even\nmodify the URL. The handler should return this object.\n\nIf, for example, you needed to add custom headers to your license request, you\ncould create a license request handler similar to this: \n\n licenseRequestHandler(networkRequestInfo) {\n if (!exoPlayerConfig) {\n return networkRequestInfo;\n }\n\n networkRequestInfo.headers =\n exoPlayerConfig.headers ? exoPlayerConfig.headers : undefined;\n\n return networkRequestInfo;\n }\n\n### Media playback info handler\n\nThe media playback info handler allows you to make changes to your playback\nconfiguration on a per media item basis. The handler is passed a [`LoadRequestData`](https://developers.google.com/cast/docs/reference/caf_receiver/cast.framework.messages.LoadRequestData)\nand a [`PlaybackConfig`](https://developers.google.com/cast/docs/reference/caf_receiver/cast.framework.PlaybackConfig.html),\nyou should return a playback config. The media playback info handler will be\ncalled before each item you Cast is loaded. If you had per-content license urls,\ncan to change them and the protection system before the load. \n\n mediaPlaybackInfoHandler(loadRequest, playbackConfig) {\n if (!exoPlayerConfig) {\n return;\n }\n\n playbackConfig.licenseUrl = exoPlayerConfig.licenseUrl ?\n exoPlayerConfig.licenseUrl :\n undefined;\n playbackConfig.protectionSystem = exoPlayerConfig.protectionSystem ?\n exoPlayerConfig.protectionSystem :\n undefined;\n\n return playbackConfig;\n }\n\nFurther resources\n-----------------\n\nEach DRM implementation is custom and this code is provided as a demonstration\nonly. You should consult your DRM provider to ensure you have correctly\nimplemented DRM in your ExoPlayer and Cast applications.\n\n[ExoPlayer's Website](https://exoplayer.dev/) features up-to-date documentation\nand announcements. Issues with ExoPlayer and its Cast integration can be\nreported at [ExoPlayer's GitHub](https://github.com/google/ExoPlayer)\nrepository."]]