0

I am setting a HttpCookie in my android application associated with a domain within the cookieManager. Then, when I stream HLS videos using exo player, I want this cookie to used for each of the .ts chunk requests.

This is the code, I use to store the cookie in the Application section of the project:

        String url1 = "http://sdtest.vzvisp.com";
        URI auri1 = null;
        try {
            auri1 = new URI(url1);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }

        AppGlobal.cookieManager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
        AppGlobal.cookieManager.getCookieStore().add(auri1, new HttpCookie("JSESSIONID","aaaMp0uKke4gp"));
        AppGlobal.cookieManager.getCookieStore().add(auri1,new HttpCookie("JSESSIONID1","aaaMp0uKke4gasasasp"));

        AppGlobal.currentHandler = CookieHandler.getDefault();
        if (AppGlobal.currentHandler != AppGlobal.cookieManager) {
            CookieHandler.setDefault(AppGlobal.cookieManager);
        }

This is an example of a chunk request sent :

http://sdtest.vzvisp.com:22779/AppConfig/SIT/fios/hls/fios/fios_hls_1m_00004.ts?vzSvc=fU2h73FMzhPgj8w0VNqYYsQ3lVZq8jjIWr6Xfrmraq4=&vispVzKey=54038752&vispIconFg=1&vispUsr=ZPq5BrbWoSQm1nsCNTPfBA==&vispAuthSid=CIAAASAIuwE&vispExpTime=1481081538&vispAuthKey=36958733&vispAuthSign=7.23.GMoCIpxmT_k123kT3P8iJxmCF-BWmeiAXQontU11hUI

But, when I inspect the packet, I do not see the cookie sent. Can someone kindly help me out ?

Thanks.

user2284140
  • 197
  • 1
  • 4
  • 18

2 Answers2

0

My guess is that the url is a simple downloadable content. If so you can use this code:

// Create a data source factory.
 val factory = DefaultHttpDataSource.Factory().setDefaultRequestProperties(mapOf("Cookie" to cookieValue))
// Create a progressive media source pointing to a stream uri.
val mediaSource = ProgressiveMediaSource.Factory(factory).createMediaSource(MediaItem.fromUri(videoUrl));
// Create a player instance.
val player = new ExoPlayer.Builder(context).build();
// Set the media source to be played.
player.setMediaSource(mediaSource);
// Prepare the player.
player.prepare();

Another option, if you are using OkHttp, you can use OkHttpDataSourceFactory instead of DefaultHttpDataSource

Uriel Frankel
  • 14,304
  • 8
  • 47
  • 69
-1

Try doing something like this:

AppGlobal.cookieManager.setCookie("http://sdtest.vzvisp.com","JSESSIONID=aaaMp0uKke4gp; Domain=.vzvisp.com; Path=/; Version=1");

Check this ticket to see how to set hls cookie correctly:

Hope this help

lukkea
  • 3,606
  • 2
  • 37
  • 51
Emanuele Tido
  • 213
  • 1
  • 4