Android Studio - VideoView only plays videos witth https and not http

你离开我真会死。 提交于 2020-04-18 06:10:27

问题


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.


回答1:


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




回答2:


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"




回答3:


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



来源:https://stackoverflow.com/questions/59220761/android-studio-videoview-only-plays-videos-witth-https-and-not-http

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!