Exoplayer: Ts with header

Created on 3 Sep 2018  路  5Comments  路  Source: google/ExoPlayer

hi

I copy code from

https://github.com/dueeeke/dkplayer/blob/master/app/src/main/java/com/dueeeke/dkplayer/player/ExoMediaPlayer.java

And getMediaSource on case C.TYPE_HLS

I want to set header for each ts

not on m3u8 url

found https://github.com/google/ExoPlayer/issues/2003

but it look like not same Factory

how can I implement it .

thanks

question

All 5 comments

The issue you linked (#2003) seems like it answers your question already. If you set the headers in the DefaultHttpDataSourceFactory, they are applied to all http requests (m3u8 and ts).

Note that setDefaultRequestProperty is deprecated and you should use factory.getDefaultRequestProperties().set(...) instead.

Hi ,
I need to send different header for each ts.
Cause header parameter is encode by ts url....

https://xxx.com/apen/082518_01-10MU/240/ts/082518_01-10MU-4.ts
https://xxx.com/apen/082518_01-10MU/240/ts/082518_01-10MU-5.ts
....etc
parameter is hash by ts url .
How can I get ts url and send different header with each

In this case, you should create a subclass DefaultHttpDataSource and override the open(dataSpec) method with something like:

@Override
public long open(DataSpec dataSpec) throws HttpDataSourceException {
  setRequestProperty(name, value);
  super.open(dataSpec);
}

Note that the dataSpec contains the url and other information about the network request.

And instead of the DefaultHttpDataSourceFactory, you can then use something like () -> new MyCustomHttpDataSourceSubClass(...).

Its very helpful .
Thanks a lot <3

Glad to be helpful :)

Was this page helpful?
0 / 5 - 0 ratings