I'm using Android Studio and i need to add ExoPlayer in my app and i need to use a specific user-agent, so i found this MagicalExoPlayer :
https://github.com/HamidrezaAmz/MagicalExoPlayer
This "version" of ExoPlayer is very easy to use and in the readme we can see it's easy to put specific header. So i tried to put a specific user-agent like this :
HashMap<String , String> extraHeaders = new HashMap<>();
extraHeaders.put("User-Agent","My User Agent");
andExoPlayerView.setSource("STREAM_URL", extraHeaders);
But the user-agent don't change, i have the default user agent of ExoPlayer.
So how to use a specific user-agent with ExoPlayer ? (it's Better if i can use MagicalExoPlayer).
The User Agent is provided to the Exoplayer while preparing the datasource for the player. Example:
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context,"MY_USER_AGENT");
Since MagicalExoPlayer is a wrapper over Exoplayer, it has set the field to a constant. See the PublicValues.java class in the github repository. You can ask the author to expose a public setter to the field. Another way would be copy the library module to your project and change the value of User Agent in the PublicValues
class. You'll need to change the build.gradle to compile the module. I would strongly advise to ask the author and not copy over the module unless it is necessary because you'll have to manually update the module afterwards.