Android WebView 无法在 WebRTC 对等连接上显示两个视频标签
Posted
技术标签:
【中文标题】Android WebView 无法在 WebRTC 对等连接上显示两个视频标签【英文标题】:Android WebView can't display both video tags on WebRTC Peer connection 【发布时间】:2019-08-18 05:09:33 【问题描述】:我在 android 上创建了一个 Webview,对 Manifest 具有所有必需的权限,然后我尝试显示一个带有 WebRTC 对等连接示例的站点。但它不能同时显示两个视频。它只显示调用者而不显示接收者。
Android Screen Preview
WebView 中的网站:https://webrtc.github.io/samples/src/content/peerconnection/pc1/ 设备:三星 SM-T280 安卓:5.1.1 API:22 ABI:armeabi-v7a Play 商店: Android 系统 WebView:版本 73.0.3683.90模块分级:
apply plugin: 'com.android.application'
android
compileSdkVersion 28
defaultConfig
applicationId "com.example.webview"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
项目分级:
buildscript
repositories
google()
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:3.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
allprojects
repositories
google()
jcenter()
task clean(type: Delete)
delete rootProject.buildDir
MainActivity.java:
package com.example.webview;
import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.PermissionRequest;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
public class MainActivity extends AppCompatActivity
protected WebView webView;
protected Button button;
protected WebSettings settings;
@Override
@SuppressLint("SetjavascriptEnabled")
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.web1);
settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setMinimumFontSize(10);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
webView.setWebChromeClient(new WebChromeClient()
@Override
public void onPermissionRequest(final PermissionRequest request)
request.grant(request.getResources());
);
webView.reload();
webView.loadUrl("https://webrtc.github.io/samples/src/content/peerconnection/pc1/");
button = findViewById(R.id.button);
button.setOnClickListener(new OnClickListener()
public void onClick(View v)
webView.reload();
);
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_
android:layout_
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_
android:layout_
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Refresh"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<WebView
android:id="@+id/web1"
android:layout_
android:layout_
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >
</WebView>
</android.support.constraint.ConstraintLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.webview">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我希望两个视频标签都能显示流。
【问题讨论】:
你解决了吗?? @AmitSharma 不,我找不到答案.. 我也无法在 webView 中打开它,但对于临时解决方案,我在 chrome 的默认浏览器(Chrome)中打开它,它工作正常。 【参考方案1】:将 mediaPlaybackRequiresUserGesture 设置为 false 为我解决了这个问题。
settings.mediaPlaybackRequiresUserGesture=false
【讨论】:
非常感谢!几天来我一直在遭受同样的问题。我今天可以早点下班! 奇怪的是,如果这没有设置为 false,即使是最简单的视频摄像头示例也无法正常工作。 webrtc.github.io/samples/src/content/getusermedia/gum以上是关于Android WebView 无法在 WebRTC 对等连接上显示两个视频标签的主要内容,如果未能解决你的问题,请参考以下文章
为啥 WebView 无法打开某些本地 URL(Android)?
android studio 无法解析 webview 等等
Android webview Mixed Content无法显示图片解决
无法从 android 应用程序的 webview 检查元素