valcustomDrmSessionManager:DrmSessionManager=CustomDrmSessionManager()// Pass a drm session manager provider to the media source factory.valmediaSourceFactory=DefaultMediaSourceFactory(context).setDrmSessionManagerProvider{customDrmSessionManager}
Java
DrmSessionManagercustomDrmSessionManager=newCustomDrmSessionManager(/* ... */);// Pass a drm session manager provider to the media source factory.MediaSource.FactorymediaSourceFactory=newDefaultMediaSourceFactory(context).setDrmSessionManagerProvider(mediaItem->customDrmSessionManager);
[[["容易理解","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-27 (世界標準時間)。"],[],[],null,["# Digital rights management\n\nExoPlayer uses Android's [`MediaDrm`](/reference/android/media/MediaDrm) API to support DRM-protected playback.\nThe minimum Android versions required for different supported DRM schemes, along\nwith the streaming formats for which they're supported, are described in the\nfollowing table:\n\n| DRM scheme | Android version number | Android API level | Supported formats |\n|-------------------------|------------------------|-------------------|----------------------------------------|\n| Widevine \"cenc\" | 4.4 | 19 | DASH, HLS (FMP4 only) |\n| Widevine \"cbcs\" | 7.1 | 25 | DASH, HLS (FMP4 only) |\n| ClearKey \"cenc\" | 5.0 | 21 | DASH |\n| PlayReady SL2000 \"cenc\" | Android TV | Android TV | DASH, SmoothStreaming, HLS (FMP4 only) |\n\nIn order to play DRM-protected content with ExoPlayer, the UUID of the DRM\nsystem must be specified\n[when building a media item](/media/media3/exoplayer/media-items#protected-content), and other\nproperties can also be provided. The player will then use these properties to\nbuild a default implementation of `DrmSessionManager`, called\n`DefaultDrmSessionManager`, that's suitable for most use cases. For some use\ncases, additional DRM properties may be necessary, as outlined in the following\nsections.\n\n### Key rotation\n\nTo play streams with rotating keys, pass `true` to\n`MediaItem.DrmConfiguration.Builder.setMultiSession` when building the media\nitem.\n\n### Multi-key content\n\nMulti-key content consists of multiple streams, where some streams use different\nkeys than others. Multi-key content can be played in one of two ways, depending\non how the license server is configured.\n\n##### Case 1: License server responds with all keys for the content\n\nIn this case, the license server is configured so that when it receives a\nrequest for one key, it responds with all keys for the content. This case is\nhandled by ExoPlayer without the need for any special configuration. Adaptation\nbetween streams (e.g. SD and HD video) is seamless even if they use different\nkeys.\n\nWhere possible, we recommend configuring your license server to behave in this\nway. It's the most efficient and robust way to support playback of multikey\ncontent, because it doesn't require the client to make multiple license requests\nto access the different streams.\n\n##### Case 2: License server responds with requested key only\n\nIn this case, the license server is configured to respond with only the key\nspecified in the request. Multi-key content can be played with this license\nserver configuration by passing `true` to\n`MediaItem.DrmConfiguration.Builder.setMultiSession` when building the media\nitem.\n\nWe do not recommend configuring your license server to behave in this way. It\nrequires extra license requests to play multi-key content, which is less\nefficient and robust than the alternative described above.\n\n### Offline keys\n\nAn offline key set can be loaded by passing the key set ID to\n`MediaItem.DrmConfiguration.Builder.setKeySetId` when building the media item.\nThis allows playback using the keys stored in the offline key set with the\nspecified ID.\n| **[Known issue #3872:](https://github.com/google/ExoPlayer/issues/3872)** Only one offline key set can be specified per playback. As a result, offline playback of multi-key content is currently supported only when the license server is configured as described in Case 1 above.\n\n### DRM sessions for clear content\n\nUse of placeholder `DrmSessions` allows `ExoPlayer` to use the same decoders for\nclear content as are used when playing encrypted content. When media contains\nboth clear and encrypted sections, you may want to use placeholder `DrmSessions`\nto avoid re-creation of decoders when transitions between clear and encrypted\nsections occur. Use of placeholder `DrmSessions` for audio and video tracks can\nbe enabled by passing `true` to\n`MediaItem.DrmConfiguration.Builder.forceSessionsForAudioAndVideoTracks` when\nbuilding the media item.\n\n### Using a custom DrmSessionManager\n\nIf an app wants to customise the `DrmSessionManager` used for playback, they can\nimplement a `DrmSessionManagerProvider` and pass this to the\n`MediaSource.Factory` which is [used when building the player](/guide/topics/media/exoplayer/media-sources#customizing-media-source-creation). The provider can\nchoose whether to instantiate a new manager instance each time or not. To always\nuse the same instance: \n\n### Kotlin\n\n```kotlin\nval customDrmSessionManager: DrmSessionManager = CustomDrmSessionManager()\n// Pass a drm session manager provider to the media source factory.\nval mediaSourceFactory =\n DefaultMediaSourceFactory(context).setDrmSessionManagerProvider { customDrmSessionManager }\n```\n\n### Java\n\n```java\nDrmSessionManager customDrmSessionManager = new CustomDrmSessionManager(/* ... */ );\n// Pass a drm session manager provider to the media source factory.\nMediaSource.Factory mediaSourceFactory =\n new DefaultMediaSourceFactory(context)\n .setDrmSessionManagerProvider(mediaItem -\u003e customDrmSessionManager);\n```\n\n\u003cbr /\u003e\n\n### Improving playback performance\n\nIf you're experiencing video stuttering when playing DRM-protected content on a\ndevice running any version of Android from Android 6.0 (API level 23) up to and\nincluding Android 11 (API level 30), you can try [enabling asynchronous buffer\nqueueing](/guide/topics/media/exoplayer/customization#enabling-asynchronous-buffer-queueing)."]]