Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exoplayer2 change HLS http headers

I am trying to change the http headers sent when using HLS. This is what my current code looks like:

private MediaSource buildMediaStore(String streamUrl) {
    Uri streamUri = Uri.parse(streamUrl);

    HttpDataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory("custom_player", defaultBandwidthMeter);
    return new HlsMediaSource.Factory(dataSourceFactory).setExtractorFactory(new DefaultHlsExtractorFactory()).createMediaSource(streamUri);
}

How would I do it? I thought about using the built HttpDataSource but I couldn't pass it into HlsMediaSource or HlsMediaSource.Factory from my knowledge.

like image 706
xSlendiX Gaming Avatar asked Feb 14 '26 11:02

xSlendiX Gaming


1 Answers

As far as I'm aware, it should be

dataSourceFactory.getDefaultRequestProperties().set("Some Header Key", "Header Value");

I will edit this with something to back me up if I can find it

Edit: https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/upstream/HttpDataSource.BaseFactory.html

You can use getDefaultRequestProperties on DataSource.Factory or HttpDataSource.Factory

like image 99
Brendan Jennings Avatar answered Feb 15 '26 23:02

Brendan Jennings