From 9b31d9f73b5df067243612319f91e38c91de8077 Mon Sep 17 00:00:00 2001 From: Littlegnal <8847263+littleGnAl@users.noreply.github.com> Date: Wed, 27 Oct 2021 18:05:54 +0800 Subject: [PATCH] doc: doc how to use RtcEnginePlugin (#482) --- README.md | 8 ++++++++ README.zh.md | 8 ++++++++ .../src/main/java/io/agora/rtc/base/RtcEnginePlugin.kt | 3 +++ ios/Classes/Base/RtcEnginePlugin.h | 5 ++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ce6caa112..5600dbd70 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,14 @@ Open the `Info.plist` and add: Your application can still run the voice call when it is switched to the background if the background mode is enabled. Select the app target in Xcode, click the **Capabilities** tab, enable **Background Modes**, and check **Audio, AirPlay, and Picture in Picture**. +## Interact with RtcEngine/AgoraRtcEngineKit on Android/iOS + +`agora_rtc_engine` has not implemented all the features of agora native (Android/iOS) sdk, due to performance reasons, such as [Custom Audio Source and Renderer](https://docs.agora.io/en/Video/custom_audio_android?platform=Android), [Custom Video Source and Renderer](https://docs.agora.io/en/Video/custom_video_android?platform=Android), [Raw Audio Data](https://docs.agora.io/en/Video/raw_data_audio_android?platform=Android), etc. `agora_rtc_engine` provides [RtcEnginePlugin](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/android/src/main/java/io/agora/rtc/base/RtcEnginePlugin.kt)/[RtcEnginePlugin](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/ios/Classes/Base/RtcEnginePlugin.h), allowing you to to interact with the [RtcEngine](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/lib/src/rtc_engine.dart) created on the Flutter side in the Android/iOS code, you can implement your own plugin by inheriting [RtcEnginePlugin](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/android/src/main/java/io/agora/rtc/base/RtcEnginePlugin.kt)/[RtcEnginePlugin](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/ios/Classes/Base/RtcEnginePlugin.h), and get the [RtcEngine](https://docs.agora.io/en/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_rtc_engine.html)/[AgoraRtcEngineKit](https://docs.agora.io/en/Video/API%20Reference/oc/Classes/AgoraRtcEngineKit.html) in the `onRtcEngineCreated` callback. Please note that you should not call the [RtcEngine.destroy](https://docs.agora.io/en/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_rtc_engine.html#afb808cdc9025a77af7dd2bce98311bfe)/[AgoraRtcEngineKit.destroy](https://docs.agora.io/en/Video/API%20Reference/oc/Classes/AgoraRtcEngineKit.html#//api/name/destroy) function on Android/iOS code, because it will affect the [RtcEngine](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/lib/src/rtc_engine.dart) on the Flutter side. To see how to use `RtcEnginePlugin`, please check the custom audio source example: + +Android:[CustomAudioPlugin.kt](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/example/android/app/src/main/kotlin/io/agora/agora_rtc_engine_example/custom_audio_source/CustomAudioPlugin.kt) + +iOS:[CustmoAudioSourcePlugin.swift](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/example/ios/Runner/CustomAudioSource/CustmoAudioSourcePlugin.swift) + ## Error handling ### Android build error diff --git a/README.zh.md b/README.zh.md index ed5078f9b..62e12d795 100644 --- a/README.zh.md +++ b/README.zh.md @@ -51,6 +51,14 @@ Agora 视频 SDK 需要 `摄像头` 和 `麦克风` 权限来开始视频通话 您的程序可以在后台运行音视频通话,前提是您开启了后台模式。在 Xcode 中选择您的 app target,点击 **Capabilities** 标签,开启 **Background Modes**,并且检查 **Audio、AirPlay 和 Picture in Picture**。 +## 在Android/iOS中与[RtcEngine](https://docs.agora.io/cn/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_rtc_engine.html)/[AgoraRtcEngineKit](https://docs.agora.io/cn/Video/API%20Reference/oc/Classes/AgoraRtcEngineKit.html)交互 + +由于性能原因,`agora_rtc_engine`暂时没有实现agora native(Android/iOS) sdk的所有功能,如[自定义音频采集和渲染](hhttps://docs.agora.io/cn/Video/custom_audio_android?platform=Android),[自定义视频采集和渲染](https://docs.agora.io/cn/Video/custom_video_android?platform=Android),[原始音频数据](https://docs.agora.io/cn/Video/raw_data_audio_android?platform=Android)等功能,`agora_rtc_engine`提供[RtcEnginePlugin](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/android/src/main/java/io/agora/rtc/base/RtcEnginePlugin.kt)/[RtcEnginePlugin](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/ios/Classes/Base/RtcEnginePlugin.h),允许你在Android/iOS代码中与Flutter端创建的[RtcEngine](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/lib/src/rtc_engine.dart)交互,你可以继承[RtcEnginePlugin](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/android/src/main/java/io/agora/rtc/base/RtcEnginePlugin.kt)/[RtcEnginePlugin](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/ios/Classes/Base/RtcEnginePlugin.h)实现自己的插件,在`onRtcEngineCreated`回调中获取[RtcEngine](https://docs.agora.io/cn/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_rtc_engine.html)/[AgoraRtcEngineKit](https://docs.agora.io/cn/Video/API%20Reference/oc/Classes/AgoraRtcEngineKit.html),请注意不要在Android/iOS中调用[RtcEngine.destroy](https://docs.agora.io/cn/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_rtc_engine.html#afb808cdc9025a77af7dd2bce98311bfe)/[AgoraRtcEngineKit.destroy](https://docs.agora.io/cn/Video/API%20Reference/oc/Classes/AgoraRtcEngineKit.html#//api/name/destroy)方法,因为这会影响Flutter端的[RtcEngine](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/lib/src/rtc_engine.dart)功能。如何使用`RtcEnginePlugin`,请查看我们提供的音频自采集demo: + +Android:[CustomAudioPlugin.kt](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/example/android/app/src/main/kotlin/io/agora/agora_rtc_engine_example/custom_audio_source/CustomAudioPlugin.kt) + +iOS:[CustmoAudioSourcePlugin.swift](https://github.com/AgoraIO/Agora-Flutter-SDK/blob/master/example/ios/Runner/CustomAudioSource/CustmoAudioSourcePlugin.swift) + ## 常见问题 ### iOS 无法显示视频(Android 是好的) diff --git a/android/src/main/java/io/agora/rtc/base/RtcEnginePlugin.kt b/android/src/main/java/io/agora/rtc/base/RtcEnginePlugin.kt index a5f90b4e8..a688286df 100644 --- a/android/src/main/java/io/agora/rtc/base/RtcEnginePlugin.kt +++ b/android/src/main/java/io/agora/rtc/base/RtcEnginePlugin.kt @@ -12,6 +12,9 @@ interface RtcEnginePlugin { * This callback will be called when the [RtcEngine] is created by * [RtcEngine.createWithContext](https://docs.agora.io/cn/Video/API%20Reference/flutter/agora_rtc_engine/RtcEngine/createWithContext.html) * function from flutter. + * + * NOTE that you should not call [RtcEngine.destroy], because it will also destroy the `RtcEngine` + * used by flutter side. * * @param rtcEngine The same [RtcEngine] used by flutter side */ diff --git a/ios/Classes/Base/RtcEnginePlugin.h b/ios/Classes/Base/RtcEnginePlugin.h index 1f4d19703..93d89eef8 100644 --- a/ios/Classes/Base/RtcEnginePlugin.h +++ b/ios/Classes/Base/RtcEnginePlugin.h @@ -13,8 +13,11 @@ NS_ASSUME_NONNULL_BEGIN * This callback will be called when the `RtcEngine` is created by [RtcEngine.createWithContext](https://docs.agora.io/cn/Video/API%20Reference/flutter/agora_rtc_engine/RtcEngine/createWithContext.html) * function from flutter. + + * NOTE that you should not call `AgoraRtcEngineKit.destroy`, because it will also destroy the `RtcEngine` + * used by flutter side. * - * @param rtcEngine The same [RtcEngine] used by flutter side + * @param rtcEngine The same `AgoraRtcEngineKit` used by flutter side */ - (void)onRtcEngineCreated:(AgoraRtcEngineKit *_Nullable)rtcEngine;