How to download video for offline with cookies in Android Bitmovin player using OfflineContentManager

We are using Bitmovin version 3.48.0 in our project.

projectMinSdkVersion = 23
projectTargetSdkVersion = 33
projectCompileSdkVersion = 33

We want to download the secured video content which is saved in chunks over server and to access the secured video content we are using below mentioned cookies.

I would like to know how to use or pass cookies to download this secured video content using bit movie player.

Map<String, List<String>> map = new HashMap<>();

map.put("**Policy**", new ArrayList<>(Collections.singleton(mediaCookies.getMediaCookie().getCloudFrontPolicy())));
map.put("**Signature**", new ArrayList<>(Collections.singleton(mediaCookies.getMediaCookie().getCloudFrontSignature())));
map.put("**Key-Pair-Id**", new ArrayList<>(Collections.singleton(mediaCookies.getMediaCookie().getCloudFrontKeyPairId())));

SourceConfig config = new SourceConfig(cookiesUrl, SourceType.*Hls*);
config.setTitle(offlineDocuments.getVideoTitle());
config.setPosterSource(offlineDocuments.getThumbnailUrl());
config.setDescription(offlineDocuments.getSummary());

offlineContentManager = OfflineContentManager.getOfflineContentManager(
config,
offlineAppVideoPath,
videoUID,
listener,
getApplicationContext()
);
Task failed: application/x-mpegURL:/data/data/com.android.package.debug/offline/video/TURVMU5UUTJOVWhWVldaa1ltSmxZZw0:0:1, false
                                                                                                      com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 403
                                                                                                          at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:419)
                                                                                                          at com.bitmovin.player.core.p0.r.open(SourceFile:4)
                                                                                                          at com.bitmovin.player.core.p0.e.open(SourceFile:16)
                                                                                                          at com.google.android.exoplayer2.upstream.TeeDataSource.open(TeeDataSource.java:60)
                                                                                                          at com.google.android.exoplayer2.upstream.cache.CacheDataSource.openNextSource(CacheDataSource.java:802)
                                                                                                          at com.google.android.exoplayer2.upstream.cache.CacheDataSource.open(CacheDataSource.java:615)
                                                                                                          at com.google.android.exoplayer2.upstream.cache.CacheWriter.readBlockToCache(CacheWriter.java:180)
                                                                                                          at com.google.android.exoplayer2.upstream.cache.CacheWriter.cache(CacheWriter.java:142)
                                                                                                          at com.google.android.exoplayer2.offline.SegmentDownloader$SegmentDownloadRunnable.doWork(SegmentDownloader.java:509)
                                                                                                          at com.google.android.exoplayer2.offline.SegmentDownloader$SegmentDownloadRunnable.doWork(SegmentDownloader.java:486)
                                                                                                          at com.google.android.exoplayer2.util.RunnableFutureTask.run(RunnableFutureTask.java:130)
                                                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
                                                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
                                                                                                          at java.lang.Thread.run(Thread.java:1012)

Thanks

Hi @ankurrathe

Thank you for contacting the Bitmovin Community.

Regarding your question about using cookies on Android, we have a tutorial available. Please refer to it to see if it meets your requirements:

How to send cookies along with requests in the Player SDKs.

As a test, when I included the following test data as cookies in the source URL along with the tutorial’s CookieManager configuration, the cookies were successfully sent:

val sourceUrl = "https://your-source-url.mpd"

// Example test data for cookies
val map: Map<String, List<String>> = mapOf(
    "Policy" to listOf("testPolicy"),
    "Signature" to listOf("testSignature"),
    "Key-Pair-Id" to listOf("testKeyPairId")
)

for ((key, valueList) in map) {
    for (value in valueList) {
        val cookie = HttpCookie(key, value)
        DEFAULT_COOKIE_MANAGER.cookieStore.add(URI(sourceUrl), cookie)
    }
}

Hope this method provides a solution for you. If you have any further questions, please let us know. Thank you.

Best Regards,
Kazuhide