Android MediaPlayer won't play music on API 26+
You need to define a res/xml/network_security_config.xml
and permit HTTP
for that host:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">server.com</domain>
</domain-config>
</network-security-config>
That network_security_config.xml
also needs to be referenced in the Manifest.xml
:
<?xml version="1.0" encoding="utf-8"?>
<manifest
...>
<application
android:networkSecurityConfig="@xml/network_security_config"
...>
...
</application>
</manifest>
The SDK documentation explains it all in detail - and this applies to all network traffic an app creates.
Instead of lowering the security standards, upgrading the connection to HTTPS
should be preferred.
And concerning that one deprecated method .setAudioStreamType()
, use .setAudioAttributes() instead - as your code already does. It does not seem to be the "main problem" here; verified that.