在许多社交媒体应用(例如WhatsApp,Instagram,Facebook等)中,视频通话成为最苛刻的功能。不仅如此,还有其他一些应用程序仅可提供此功能,以将Duo等世界各地的人们彼此联系起来。因此,这使我们对视频通话的重要性有了一个想法。因此,在本文中,我们将使用Jitsi开发自己的视频通话应用程序。现在,在不浪费更多时间的情况下,让我们看一下该视频通话应用程序在Android中的实现。
我们将在本文中构建什么?
在本文中,我们将开发一个示例应用程序,该应用程序的MainActivity中将包含一个EditText和一个Button。使用EditText,我们将为我们命名一个房间进行视频通话,然后,单击“按钮”,我们将加入该房间,并以创建的房间的名称打开一个新活动,最后,通过使用此活动,我们将进行视频通话打电话。下面提供了一个示例视频,以使您对我们在本文中将要做的事情有个大概的了解。注意,我们将使用Java语言实现该项目。
使用Jitsi Meet SDK逐步实现视频通话应用程序
步骤1:创建一个新项目
要在Android Studio中创建新项目,请参阅如何在Android Studio中创建/启动新项目。请注意,选择Java作为编程语言。选择最低的SDK 21或更高版本。
步骤2:添加jitsi maven存储库
现在,转到根目录build.gradle(Project)并将这些行添加到allprojects {}部分内jcenter()下方的存储库末尾。
allprojects {
repositories {
…
maven { url “https://github.com/jitsi/jitsi-maven-repository/raw/master/releases” }
}
}
步骤3:添加依赖项
现在,导航到Gradle脚本> build.gradle(Module:app)在依赖项部分添加以下依赖项。
implementation(‘org.jitsi.react:jitsi-meet-sdk:2.9.0’) { transitive = true }
步骤4:在build.gradle(Module:app)中添加Java 1.8兼容性支持
现在,要向项目添加Java 1.8兼容性支持,请将这些行粘贴到android {}标记内的buildTypes {}下(如果尚不存在的话)。
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
第5步:添加Proguard规则
现在,我们将添加一些proguard规则,因此请转到Gradle脚本> proguard-rules.pro并粘贴以下行。
Reference: https://github.com/jitsi/jitsi-meet/blob/master/android/app/proguard-rules.pro
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# React Native
# Keep our interfaces so they can be used by other ProGuard rules.
# See http://sourceforge.net/p/proguard/bugs/466/
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.proguard.annotations.DoNotStrip class *
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
@com.facebook.proguard.annotations.DoNotStrip *;
@com.facebook.common.internal.DoNotStrip *;
}
-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
void set*(***);
*** get*();
}
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
-keepclassmembers,includedescriptorclasses class * { native ; }
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; }
-dontwarn com.facebook.react.**
-keep,includedescriptorclasses class com.facebook.react.bridge.** { *; }
# okhttp
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
# okio
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-keep class okio.** { *; }
-dontwarn okio.**
# WebRTC
-keep class org.webrtc.** { *; }
-dontwarn org.chromium.build.BuildHooksAndroid
# Jisti Meet SDK
-keep class org.jitsi.meet.** { *; }
-keep class org.jitsi.meet.sdk.** { *; }
# We added the following when we switched minifyEnabled on. Probably because we
# ran the app and hit problems...
-keep class com.facebook.react.bridge.CatalystInstanceImpl { *; }
-keep class com.facebook.react.bridge.ExecutorToken { *; }
-keep class com.facebook.react.bridge.JavaScriptExecutor { *; }
-keep class com.facebook.react.bridge.ModuleRegistryHolder { *; }
-keep class com.facebook.react.bridge.ReadableType { *; }
-keep class com.facebook.react.bridge.queue.NativeRunnable { *; }
-keep class com.facebook.react.devsupport.** { *; }
-dontwarn com.facebook.react.devsupport.**
-dontwarn com.google.appengine.**
-dontwarn com.squareup.okhttp.**
-dontwarn javax.servlet.**
# ^^^ We added the above when we switched minifyEnabled on.
# Rule to avoid build errors related to SVGs.
-keep public class com.horcrux.svg.** {*;}
最后,同步您的项目,现在我们拥有实施过程中所需的一切,因此,现在就开始实施吧。
步骤6:使用activity_main.xml文件
现在是时候设计应用程序的布局了。因此,请转到应用> res> layout> activity_main.xml,然后将下面编写的代码粘贴到activity_main.xml文件中。
XML
Java
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import org.jitsi.meet.sdk.JitsiMeetActivity;
import org.jitsi.meet.sdk.JitsiMeetConferenceOptions;
import java.net.MalformedURLException;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// using try catch block to handle exceptions
try {
// object creation of JitsiMeetConferenceOptions
// class by the name of options
JitsiMeetConferenceOptions options = new JitsiMeetConferenceOptions.Builder()
.setServerURL(new URL(""))
.setWelcomePageEnabled(false)
.build();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
// we have declared the name of onButtonClick() method
// in our xml file now we are going to define it.
public void onButtonClick(View v) {
// initialize editText with method findViewById()
// here editText will hold the name of room which is given by user
EditText editText = findViewById(R.id.conferenceName);
// store the string input by user in editText in
// an local variable named text of string type
String text = editText.getText().toString();
// if user has typed some text in
// EditText then only room will create
if (text.length() > 0) {
// creating a room using JitsiMeetConferenceOptions class
// here .setRoom() method will set the text in room name
// here launch method with launch a new room to user where
// they can invite others too.
JitsiMeetConferenceOptions options
= new JitsiMeetConferenceOptions.Builder()
.setRoom(text)
.build();
JitsiMeetActivity.launch(this, options);
}
}
}
步骤7:使用MainActivity。 Java文件
转到应用> Java >程序包名称> MainActivity。 Java文件并参考以下代码。下面是MainActivity的代码。 Java文件。在代码内部添加了注释,以更详细地了解代码。
Java
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import org.jitsi.meet.sdk.JitsiMeetActivity;
import org.jitsi.meet.sdk.JitsiMeetConferenceOptions;
import java.net.MalformedURLException;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// using try catch block to handle exceptions
try {
// object creation of JitsiMeetConferenceOptions
// class by the name of options
JitsiMeetConferenceOptions options = new JitsiMeetConferenceOptions.Builder()
.setServerURL(new URL(""))
.setWelcomePageEnabled(false)
.build();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
// we have declared the name of onButtonClick() method
// in our xml file now we are going to define it.
public void onButtonClick(View v) {
// initialize editText with method findViewById()
// here editText will hold the name of room which is given by user
EditText editText = findViewById(R.id.conferenceName);
// store the string input by user in editText in
// an local variable named text of string type
String text = editText.getText().toString();
// if user has typed some text in
// EditText then only room will create
if (text.length() > 0) {
// creating a room using JitsiMeetConferenceOptions class
// here .setRoom() method will set the text in room name
// here launch method with launch a new room to user where
// they can invite others too.
JitsiMeetConferenceOptions options
= new JitsiMeetConferenceOptions.Builder()
.setRoom(text)
.build();
JitsiMeetActivity.launch(this, options);
}
}
}
仅此而已,现在可以在设备上安装视频通话应用程序了。这是应用程序输出的样子。
输出:在物理设备上运行
Github链接:有关更多帮助,请访问此存储库。