This page introduces how to integrate and use the BytePlus Effects extension in your Android or iOS app.
The BytePlus Effects extension encapsulates the core APIs of the BytePlus Effects SDK. By calling the setExtensionProperty or setExtensionPropertyWithVendor method of the Agora Video SDK v4.0.0 and passing in the corresponding key
and value
, you can quickly integrate BytePlus's capabilities.
Taking setExtensionProperty
as an example, the key
is named after the BytePlus API, and the value
wraps either certain or all of the parameters of that API in JSON. When you call setExtensionProperty
and pass in the pair of key
and value
, it is equivalent to calling the corresponding BytePlus API. The case is the same for setExtensionPropertyWithVendor
.
The BytePlus Effects extension works together with the Agora Video SDK v4.x. Refer to the following docs to integrate the SDK and start a basic video call:
Android
.aar
files to the /app/libs
path of your project folder./app/src/main/assets
path of the project folder. For details, see Resource package structure.app/build.gradle
file, add the following line in dependencies
:implementation fileTree(dir: "libs", include: ["*.jar", "*.aar"])
import io.agora.rtc2.Constants;
import io.agora.rtc2.IMediaExtensionObserver;
import io.agora.rtc2.IRtcEngineEventHandler;
import io.agora.rtc2.RtcEngine;
import io.agora.rtc2.RtcEngineConfig;
import io.agora.rtc2.video.VideoCanvas;
import io.agora.rte.extension.bytedance.ExtensionManager;
iOS
Resource
folder under your project folder, as follows:.
├── <ProjectName>
├── <ProjectName>.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ └── xcshareddata
└── Resource
.framework
files to the <ProjectName>
path.Resource
path. For details, see Resource package structure. #import <AgoraRtcKit/AgoraRtcEngineKit.h>
#import "BDResourceHelper.h"
This section describes the call sequence of using the extension. For a detailed parameter description, see the API Reference.
Android
When initializing RtcEngine
, call enableExtension
to enable the extension:
private void enableExtension(boolean enabled) {
// Initialize ExtensionManager before calling enableExtension
ExtensionManager.getInstance(mRtcEngine).initialize(this);
mRtcEngine.enableExtension("ByteDance", "Effect", enabled);
}
iOS
When initializing AgoraRtcEngineKit
, call enableExtensionWithVendor
to enable the extension:
[self.agoraKit enableExtensionWithVendor:@"ByteDance"
extension:@"Effect"
enabled:self.enable];
To initialize the extension, call setExtensionProperty
(Android) or setExtensionPropertyWithVendor
(iOS), and pass in the corresponding keys and values:
bef_effect_ai_check_license
and the value as the path of the license file LicenseBag.bundle
.bef_effect_ai_init
and the value as the path of the model file ModelResource.bundle
and the device name.Take Android as an example:
private void initExtension() {
String[] resources = new String[] {"byte_dance/LicenseBag.bundle", "byte_dance/ModelResource.bundle"};
loadBundle(resources, () -> {
File destFile = getExternalFilesDir(null);
// Gets the path of the license file
File licensePath = new File(
destFile,
"byte_dance/LicenseBag.bundle/" + io.agora.rte.extension.bytedance.example.Constants.mLicenseName);
// Check the license
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("licensePath", licensePath.getPath());
setExtensionProperty("bef_effect_ai_check_license", jsonObject.toString());
} catch (JSONException e) {
Log.e(TAG, e.toString());
}
// Gets the path of the model file
File strModelDir = new File(destFile, "byte_dance/ModelResource.bundle");
// Initializes the effects
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("strModelDir", strModelDir.getPath());
jsonObject.put("deviceName", "");
setExtensionProperty("bef_effect_ai_init", jsonObject.toString());
} catch (JSONException e) {
Log.e(TAG, e.toString());
}
// Set whether the overlay effects can coexist with stickers
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("mode", 1);
jsonObject.put("orderType", 0);
setExtensionProperty("bef_effect_ai_composer_set_mode", jsonObject.toString());
} catch (JSONException e) {
Log.e(TAG, e.toString());
}
});
}
// Only updates the key and value when calling setExtensionProperty
private void setExtensionProperty(String key, String property) {
mRtcEngine.setExtensionProperty("ByteDance", "Effect", key, property);
}
Call setExtensionProperty
(Android) or setExtensionPropertyWithVendor
(iOS), and pass in the corresponding keys and values. You can implement the following functions:
You can call the method as needed. For a full list of keys and values, see the API Reference.
The complete sample code and project is provided on GitHub:
Platform | Language | Sample project |
---|---|---|
Android | Java | ByteDance/android |
iOS | Objective-C | ByteDance/ios |
For a detailed parameter description, see the API Reference.