Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: ExoPlayer: create MediaSource from DefaultHttpDataSource

I use ExoPlayer for playback of videos from url in my app and need to set an authorization header for each video. DefaultHttpDataSource can be used for that. For example,

DefaultHttpDataSource source = new DefaultHttpDataSource(Util.getUserAgent(mContext, "appAgent"), null);
            source.setRequestProperty("Authorization", authToken);

MediaSource is needed to prepare the player. The question is how to create a MediaSource based on DefaultHttpDataSource? Both of the constructors of ExtractorMediaSource require DataSource.Factory, not DataSource.

like image 923
Dubrovin Avatar asked Oct 18 '22 00:10

Dubrovin


1 Answers

This returns a Datasource.Factory object:

return new DefaultDataSourceFactory(this, null, new DefaultHttpDataSourceFactory(Util.getUserAgent(mContext, "appAgent"), null));

like image 63
devnullpointer Avatar answered Oct 27 '22 10:10

devnullpointer