I have been working on an android app for live streaming and I used videoview as a player , but it only streams videos with https and throws a message "Can't play this video" if the link starts with http , that only happens on my real device not the emulator , how can I open access for http ? or how can I solve that problem actually.
3 Answers
here is the solution actually d this
I have added this code to my Manifest and it worked all well !
android:usesCleartextTraffic="true"
solution taken from this problem

- 73
- 2
- 8
As you didn't share your code I suppose you used [setVideoURI(Uri uri)] so what I purpose is to use [setOnErrorListener()] and find out the reason the video isn't playing then work on solving it. check this out : https://developer.android.com/reference/android/widget/VideoView.html#setOnErrorListener(android.media.MediaPlayer.OnErrorListener)
and as it works on the emulator the problem could be that the emulator allow http but the phone blocks it for security . so maybe the following link would be useful: Android - Video streaming over local HTTPS server: SSL certificate rejected

- 11
- 3
Just follow the steps
1) Make xml folder is res then make a xml resource file in xml folder (newtwork_security.xml) then copy the below lines in it.
<?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>
2) Go to your manifest file inside application
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--Content-->
</application>
give the name of your file in networkSecurityConfig = "Your file"

- 189
- 4
- 19