ホームページ  >  記事  >  Java  >  ZEGOCLOUDでビデオ通話アプリを作る方法

ZEGOCLOUDでビデオ通話アプリを作る方法

DDD
DDDオリジナル
2024-09-25 06:24:07686ブラウズ

How to Make a Video Call App with ZEGOCLOUD

想要建立自己的視訊通話應用程式嗎?多虧了 ZEGOCLOUD,這比您想像的要容易。本指南將向您展示如何逐步建立視訊通話應用程式。 ZEGOCLOUD 提供的工具可以讓流程變得簡單,即使您是應用程式開發新手。

您將學習如何設定專案、新增視訊通話功能以及如何讓應用程式順利運作。我們將介紹您需要了解的基礎知識,從 ZEGOCLOUD 入門到測試您完成的應用程式。最後,您將擁有一個自己建立的可用視訊通話應用程式。

無論您是初學者還是有一定的編碼經驗,本指南都將幫助您使用ZEGOCLOUD快速輕鬆地創建視訊通話應用程式。

製作一個應用程式需要多長時間?

建立應用程式需要時間,確切的持續時間取決於應用程式的複雜性和功能。具有基本功能的簡單應用程式可能需要大約 2-3 個月的時間來開發。這些應用程式通常具有最少的功能,例如幾個螢幕和標準功能。

另一方面,包含用戶身份驗證、資料庫整合或即時更新等功能的更複雜的應用程式可能需要 4-6 個月或更長時間。這些應用程式需要更詳細的規劃、設計和測試,以確保一切順利運作。

影響開發時間的另一個因素是專案團隊的規模。規模較大、經驗豐富的團隊可能會比規模較小的團隊更快完成應用程式。溝通和專案管理的品質也會影響應用程式的完成速度。

還要注意的是,應用程式開發並不會在發布後結束。需要定期更新和維護來修復錯誤並保持應用程式順利運行。

整體而言,建立應用程式可能需要幾個月到一年以上的時間,具體取決於專案的範圍。良好的規劃和對應用程式要求的清晰了解有助於加快流程。

iOS 應用程式開發與 Android 應用程式開發:有什麼不同?

製作行動應用程式時,您可以選擇適用於 Apple 裝置的 iOS 或適用於許多其他手機的 Android。兩者都很受歡迎,但它們有一些關鍵的區別。讓我們來比較一下它們:

Criteria

iOS App Development

Android App Development

Programming Language Swift and Objective-C Kotlin and Java
Development Environment Xcode Android Studio
Device Fragmentation Less device variety, easier to test Wide range of devices, harder to test
App Store Approval Strict review process Less strict, faster approval
Market Share Popular in North America and Europe Dominates in Asia, Africa, and more
Development Cost Usually higher due to stricter guidelines Can be lower, but depends on the complexity
Revenue Potential Higher app revenue per user Larger audience, but lower revenue per user

主な違い:

  • プログラミング言語: iOS アプリは Swift または Objective-C で構築されますが、Android アプリは Kotlin または Java を使用します。 Swift は新しくて習得が簡単ですが、Kotlin は Android デバイス間でより多用途です。
  • デバイスの断片化: iOS 開発者が扱うデバイス モデルが減り、テストが簡素化されます。ただし、Android 開発者は、さまざまなデバイスと画面サイズを考慮する必要があります。
  • 収益の可能性: iOS アプリは、特にアプリ内購入から高い収益を生み出すことがよくあります。 Android アプリはより多くのユーザーにリーチしますが、ユーザーあたりの収益は少なくなる可能性があります。

全体として、どちらのプラットフォームにも独自の利点があり、選択は対象ユーザーと目標によって異なります。

Android および iOS 用のビデオ通話アプリを作成する方法

Android および iOS 用のビデオ通話アプリの作成は難しそうに思えるかもしれませんが、適切なツールを使えば、思ったよりも簡単に作成できます。このセクションでは、ZEGOCLOUD Express SDK を使用してこれを行う方法を説明します。

ZEGOCLOUD は、アプリにリアルタイムのビデオおよびオーディオ機能を簡単に追加できる強力なプラットフォームです。複雑な部分は処理されるため、ユーザーにスムーズなエクスペリエンスを提供することに集中できます。 ZEGOCLOUD を使用すると、Android と iOS の両方でビデオ通話アプリをすばやく簡単に構築できます。

前提条件

始める前に、必要なものがすべて揃っていることを確認してください:

  • ZEGOCLOUD 開発者アカウントにサインアップします。
  • ZEGOCLOUD 管理ダッシュボードから AppID と AppSign を取得します。
  • 上記の Android Studio 2020.3.1 または iOS アプリ用の Xcode 13.0 がインストールされています。
  • オーディオとビデオをサポートする、Android 4.4 または iOS 9.0 以降を実行しているデバイスを使用します。
  • Android または iOS アプリ開発の知識。
  • デバイスがインターネットに接続されていることを確認してください。

Androidビデオ通話アプリ

1. SDK 依存関係の追加

1.1 Gradle のセットアップ

Zego SDK を使用するには、Gradle 経由で ZegoExpress SDK を Android プロジェクトに追加する必要があります。これを行うには、以下の手順に従ってください:

  • Android Studio バージョン 7.1.0 以降の場合は、プロジェクトの settings.gradle ファイルを開きます。次のコードを dependencyResolutionManagement ブロック内に追加します。
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven { url 'https://storage.zego.im/maven' }
        google()
        mavenCentral()
    }
}
  • 古いバージョンの Android Studio の場合は、プロジェクトのルート ディレクトリにある build.gradle ファイルを開きます。 allprojects ブロック内に次のコードを追加します:

    allprojects {
    repositories {
        maven { url 'https://storage.zego.im/maven' }
        google()
        mavenCentral()
    }
    }
    

1.2 SDK 依存関係の追加

app/build.gradle ファイルを開きます。依存関係ブロック内に次の行を追加します (x.y.z を最新の SDK バージョンに置き換えます):

dependencies {
    implementation 'im.zego:express-video:x.y.z'
}

ファイルを保存し、プロジェクトを同期します。これにより ZegoExpress SDK が追加され、ビデオ通話機能が有効になります。

2. SDKのインポート

依存関係が同期されたら、Zego SDK をメイン アクティビティにインポートして、ビデオ通話機能の実装を開始できるようにします。

MainActivity.java または MainActivity.kt ファイルを開きます。次の import ステートメントを追加します:

import im.zego.zegoexpress.ZegoExpressEngine;

このインポートにより、Zego SDK のコア機能を使用できるようになります。

3. ビデオ通話機能の実装

3.1 アプリの資格情報を定義する

ZEGOCLOUD ダッシュボードから取得した AppID と AppSign を定義する必要があります。

メイン アクティビティ ファイルに、次の変数を追加します。

String appID = "c12dbc38b67451a9ee8a0ba266840aab";  // Replace with your actual AppID
String appSign = "fe1529d55bcbcc0fa462cba668b8f2bd";  // Replace with your actual AppSign

3.2 ユーザーとルーム情報の定義

次に、ユーザーとビデオ通話ルームを識別するために userID、userName、および roomID を定義します。変数を定義します:

String userID = "fc4a8a14869bc3b8f84d052a35378195";   // Replace with your actual user ID
String userName = "c157e43fc1e6147c21d7b2f420f7501f"; // Replace with your actual user name
String roomID = "93429f3717703a6e1b861e1d1565e862";   // Replace with your actual room ID

3.3 Zego エンジンの初期化

通話を開始する前に、Zego エンジンを初期化する必要があります。このエンジンはすべてのビデオ通話操作を処理します。次のメソッドを追加してエンジンを初期化します:

void createEngine() {
    ZegoEngineProfile profile = new ZegoEngineProfile();
    profile.appID = Long.parseLong(appID);
    profile.appSign = appSign;
    profile.application = getApplication();
    profile.scenario = ZegoScenario.DEFAULT; // Set the appropriate scenario
    ZegoExpressEngine.createEngine(profile, null);
}

このメソッドは、appID と appSign を使用して ZegoExpressEngine を初期化します。シナリオは DEFAULT に設定されており、一般的な使用例には問題ありません。

3.4 ビデオ通話の開始と参加

次に、ビデオ通話を開始して参加するためのメソッドを実装します。

ビデオ通話を開始する:

void startVideoCall() {
    ZegoExpressEngine.getEngine().startPublishingStream(roomID);
}

ビデオ通話に参加する:

void joinVideoCall() {
    ZegoExpressEngine.getEngine().startPlayingStream(roomID);
}

4. デバイス権限の構成

ビデオ通話でカメラとマイクにアクセスするには、AndroidManifest.xml ファイルで権限をリクエストする必要があります。 AndroidManifest.xml ファイルを開き、次の権限を追加します:

eafa53ed60cf631bb40427ba7fd27cc3
cc4be989b182b85ab53d6e27e2649273
80768a34d765d25f66049afad58fea64

Android 6.0 以降の場合は、実行時権限をリクエストする必要もあります。

String[] permissions = {"android.permission.CAMERA", "android.permission.RECORD_AUDIO"};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    requestPermissions(permissions, 101);
}

5. Android アプリの実行とテスト

権限を設定したら、Android アプリを実行してテストできるようになります。

  • Build and run your app on a real Android device.
  • Test the video call by starting the call on one device and joining the call on another using the same roomID.

iOS Video Call App

1. Adding the SDK Dependencies

1.1 Setting Up Swift Package Manager

For iOS, you will use Swift Package Manager to add the ZegoUIKitPrebuiltLiveStreaming SDK. Follow the steps below:

  • Open Xcode, and go to File > Add Packages.
  • In the search box, enter the following URL:
https://github.com/zegolibrary/express-video-ios

Select the latest version and add the package to your project.

2. Importing the SDK

Once the SDK is installed, you need to import it into your ViewController.swift file. In your ViewController.swift file, add the following import statements:

import ZegoUIKit
import ZegoUIKitPrebuiltLiveStreaming

These import statements give you access to the Zego video call SDK.

3. Implementing Video Call Functionality

3.1 Define App Credentials

You need your AppID and AppSign to authenticate your app with ZEGOCLOUD. Add the following credentials at the top of your ViewController.swift file:

let appID: UInt32 = 0122b644d0a0273642508c49a6bb2b8e  // Replace with your actual AppID
let appSign: String = "86c79318892e84f5d80aa6d0c14c7516"  // Replace with your actual AppSign

3.2 Define User and Room Information

Now, define the userID, userName, and roomID variables for identifying users and the room. Add these variables:

var userID: String = "fc4a8a14869bc3b8f84d052a35378195"   // Replace with actual user ID
var userName: String = "c157e43fc1e6147c21d7b2f420f7501f" // Replace with actual user name
var roomID: String = "93429f3717703a6e1b861e1d1565e862"   // Replace with actual room ID

3.3 Initializing the Zego Engine

Like Android, you must initialize the Zego engine on iOS to handle video call functionality. Add the function below:

func createEngine() {
    let profile = ZegoEngineProfile()
    profile.appID = appID
    profile.appSign = appSign
    ZegoExpressEngine.createEngine(with: profile, eventHandler: self)
}

This function initializes the Zego engine with your credentials.

3.4 Starting and Joining a Video Call

To start a video call as a host:

func startVideoCall() {
    ZegoExpressEngine.shared().startPublishingStream(roomID)
}

To join an existing video call:

func joinVideoCall() {
    ZegoExpressEngine.shared().startPlayingStream(roomID)
}

4. Configuring Device Permissions

In iOS, you need to request camera and microphone permissions in the Info.plist file. Open the Info.plist file and add the following keys:

42538adbdb6240b2b083a000a615d5bdNSCameraUsageDescription9780a7140ed8471d130dc57bcb9b0bd2
98c455a79ddfebb79781bff588e7b37eWe need access to your camera for video calls.dba3c644993c36696c11b074e67a4078
42538adbdb6240b2b083a000a615d5bdNSMicrophoneUsageDescription9780a7140ed8471d130dc57bcb9b0bd2
98c455a79ddfebb79781bff588e7b37eWe need access to your microphone for video calls.dba3c644993c36696c11b074e67a4078

These entries will display permission prompts when the user first opens the app.

5. Running and Testing Your Video Call App

Once your permissions are set, you can now test your app:

  • Open the .xcworkspace file in Xcode, select your target device, and run the app.
  • Start a video call on one device, then join it from another device using the same room ID to test the feature.

These are just the basics. To add more features to your video call app, explore ZEGOCLOUD’s Express Video SDK documentation. You can also get started with our sample source code!

Conclusion

Building a video call app with ZEGOCLOUD is a straightforward process, whether you're developing for Android or iOS. By following this guide, you can set up your project, integrate essential video calling features, and test the app on real devices. ZEGOCLOUD’s powerful SDK simplifies the implementation, allowing you to focus on user experience rather than complex backend processes.

Start building your custom video call app today and create seamless communication experiences for your users.

以上がZEGOCLOUDでビデオ通話アプリを作る方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。