我正在ionic4上编写流应用程序,正在手机上对其进行测试,但是我无法打开http链接...
控制台:
GET http://131.173.8.23/mjpg/video.mjpg
net :: ERR_CLEARTEXT_NOT_PERMITTED
我读到您可以解决添加network_security_config.xml
文件的问题,但是您知道吗……它不起作用! (但在我的浏览器上工作正常)
有人知道吗?
我的代码:
(network_security_config.xml)
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost:8100</domain>
<domain>131.173.8.23:80</domain>
</base-config>
</network-security-config>
(AndroidManifest)
<?xml version='1.0' encoding='utf-8'?>
<manifest
android:hardwareAccelerated="true"
android:versionCode="1"
android:versionName="0.0.1"
package="io.ionic.starter"
xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:usesCleartextTraffic="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:configChanges="orientation|screenSize" android:label="Simple Audio Stream" android:name="com.hutchind.cordova.plugins.streamingmedia.SimpleAudioStream" />
<activity android:configChanges="orientation|screenSize" android:label="Simple Video Stream" android:name="com.hutchind.cordova.plugins.streamingmedia.SimpleVideoStream" />
</application>
</manifest>
(home.page.html)
<ion-header>
<ion-toolbar>
<ion-title>
CameraLux
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-grid>
<ion-row>
<ion-col>
<video width="250" height="160" (click)="startVideo()" autoplay>
<source src="http://131.173.8.23:80/mjpg/video.mjpg"/>
</video>
</ion-col>
<ion-col>
<video width="250" height="160" autoplay>
<source src="https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4"/>
</video>
</ion-col>
<ion-col>
<video width="250" height="160" (click)="startVideo()" autoplay>
<source src="https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4"/>
</video>
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<video width="250" height="160" (click)="startVideo()" autoplay>
<source src="https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4"/>
</video>
</ion-col>
<ion-col>
<video width="250" height="160" (click)="startVideo()" autoplay>
<source src="https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4"/>
</video>
</ion-col>
<ion-col>
<video width="250" height="160" (click)="startVideo()" autoplay>
<source src="https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4"/>
</video>
</ion-col>
</ion-row>
</ion-grid>
<br/>
<br/>
<br/>
<br/>
</ion-content>
答案 0 :(得分:0)
android:networkSecurityConfig="@xml/network_security_config"
不适用于android:usesCleartextTraffic="true"
因此在您的config.xml中应该只包含
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:usesCleartextTraffic="true" />
</edit-config>
不是两者
答案 1 :(得分:-1)
添加
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:usesCleartextTraffic="true" />
</edit-config>
config.xml运行
cordova platform rm android
然后
cordova platform add android