Abhishek Kumar
Abhishek Kumar

Reputation: 31

HTTP URL is not working in the ExoPlayer for Android 10

I have an HTTP URL of audio.

The URL is working fine with the ExoPlayer v2.7.0 when android TargetSDKVersion is 26.

When the TargetSDKVersion is set to 28, it is not working.

Getting the following error:

W/MediaPlayer: Couldn't open http://***
java.io.FileNotFoundException: No content provider: http://***

But, when I set an HTTPS URL, it works fine.

For this, we have set the network configuration in the AndroidManifest

<application
        android:usesCleartextTraffic="true"
        android:networkSecurityConfig="@xml/network_security_config"

And network_security_config is:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

Also, used setAudioAttributes instead of setAudioStreamType for the media player.

mediaPlayer.setAudioAttributes(
                    new AudioAttributes
                            .Builder()
                            .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                            .build());

Any thoughts on this?

Upvotes: 2

Views: 2805

Answers (1)

Abhishek Kumar
Abhishek Kumar

Reputation: 31

I have updated the network_security_config as follows:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">my_domain.com</domain>
    </domain-config>
</network-security-config>

And removed the usesCleartextTraffic property from the AndroidManifest as follows:

<application
        <!--android:name="com.tv2consulting.TV2Application"-->
        android:networkSecurityConfig="@xml/network_security_config"

Allowing clear text traffic for a particular domain worked for me.

Upvotes: 1

Related Questions