Nikhil
Nikhil

Reputation: 931

How to set a custom 'user-agent' as header for Android Bitmovin player SDK?

I have tried the method PreprocessHttpRequestCallback for altering NetworkConfig to add a custom user agent unfortunately, I couldn't implement it successfully. I even searched their entire git sample repo for NetworkConfig yet failed to find a sample and also their documentation

There is nothing many practical examples couldn't find.

Bitmovin Android SDK Version: 3.18

Upvotes: 0

Views: 129

Answers (1)

Daniel
Daniel

Reputation: 1256

Not sure what exactly you tried, but this seems to work (replace customValue with your desired user-agent string) using the PreprocessHttpRequestCallback:

NetworkConfig networkConfig = new NetworkConfig();
PreprocessHttpRequestCallback preprocessHttpRequestCallback = new PreprocessHttpRequestCallback() {
    @Nullable
    @Override
    public Future<HttpRequest> preprocessHttpRequest(HttpRequestType httpRequestType, HttpRequest httpRequest) {

        ExecutorService executorService = Executors.newSingleThreadExecutor();
        Callable<HttpRequest> callable = () -> {
            HashMap<String, String> headers = new HashMap<>();
            headers.put("User-Agent", "customValue");
            httpRequest.setHeaders(headers);
            return httpRequest;
        };
        Future<HttpRequest> future = executorService.submit(callable);
        return future;
    }
};
networkConfig.setPreprocessHttpRequestCallback(preprocessHttpRequestCallback);
player.getConfig().setNetworkConfig(networkConfig);

A good place to ask such questions is also Bitmovin's Community: https://community.bitmovin.com/t/how-to-set-a-custom-user-agent-as-header-for-android-bitmovin-player-sdk/979/2

Upvotes: 0

Related Questions