Extensions are add-ons designed to extend the functionality of the Agora SDK. The Extensions Marketplace is home to extensions that make your app more fun. These extensions provide features such as:
This page shows you how to integrate and use an extension from the Agora Extensions Marketplace.
To use an extension in your Agora project, implement the following steps in your app:
addExtension
when you initialize RtcEngine
.enableExtension
before joining a channel.setExtensionProperty
to pass in necessary parameters.To follow the procedure on this page, you must have:
.aar
or .so
) and details about the extension. See Activate an extension.To create the environment necessary to integrate the extension into your app, do the following:
.aar
).aar
file to /app/libs
in your project folder./Gradle Scripts/build.gradle(Module: <ProjectName> app)
, add the following line under dependencies
:implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
.so
).so
file to the following paths in your project folder:/app/src/main/jniLibs/arm64-v8a
/app/src/main/jniLibs/armeabi-v7a
For demonstration purposes, a simple watermark extension is used to explain the procedure.
The watermark extension adds a watermark on video streamed to your local client. This section shows you how to implement the watermark extension in your Agora project.
.aar
files in Project setup. app/src/main/java/com.example.<projectname>/MainActivity
:import org.json.JSONException;
import org.json.JSONObject;
// ExtensionManager is used to pass in basic information about the extension
import io.agora.extension.ExtensionManager;
import io.agora.rtc2.IMediaExtensionObserver;
import io.agora.rtc2.RtcEngineConfig;
In app/src/main/java/com.example.<projectname>/MainActivity
, replace the current initializeAndJoinChannel
function with the following code:
private void initializeAndJoinChannel() {
try {
RtcEngineConfig config = new RtcEngineConfig();
config.mContext = getBaseContext();
config.mAppId = appId;
// Call addExtension to add the extension.
config.addExtension(ExtensionManager.EXTENSION_NAME);
// Register IMediaExtensionObserver to receive events from the extension.
config.mExtensionObserver = new IMediaExtensionObserver() {
@Override
public void onEvent(String vendor, String extension, String key, String value) {
// Add callback handling logics for extension events.
}
};
config.mEventHandler = mRtcEventHandler;
mRtcEngine = RtcEngine.create(config);
} catch (Exception e) {
throw new RuntimeException("Check the error.");
}
// Call enableExtension to enable the extension.
// To enable multiple extensions, call enableExtension as many times. The sequence of enabling multiple extensions determines the order of these extensions in the transmission pipeline.
// For example, if you enable extension A before extension B, extension A processes data from the SDK before extension B.
mRtcEngine.enableExtension(ExtensionManager.EXTENSION_VENDOR_NAME, ExtensionManager.EXTENSION_VIDEO_FILTER_NAME, true);
mRtcEngine.enableVideo();
mRtcEngine.startPreview();
FrameLayout container = findViewById(R.id.local_video_view_container);
SurfaceView surfaceView = new SurfaceView(getBaseContext());
container.addView(surfaceView);
mRtcEngine.setupLocalVideo(new VideoCanvas(surfaceView, VideoCanvas.RENDER_MODE_FIT, 0));
ChannelMediaOptions options = new ChannelMediaOptions();
options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER;
options.channelProfile = Constants.CHANNEL_PROFILE_LIVE_BROADCASTING;
options.publishCameraTrack = true;
mRtcEngine.joinChannel(token, channelName, 0, options);
JSONObject o = new JSONObject();
try {
// Pass in the key-value pairs defined by the extension provider to configure the feature you want to use.
o.put("plugin.watermark.wmStr", "Agora");
o.put("plugin.watermark.wmEffectEnabled", true);
// Call setExtensionProperty to use the watermark feature.
mRtcEngine.setExtensionProperty(ExtensionManager.EXTENSION_VENDOR_NAME, ExtensionManager.EXTENSION_VIDEO_FILTER_NAME, "key", o.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
To test whether the extension works properly, follow these steps:
Run app
on your Android Studio. A moment later you will see the project installed on your device.Agora provides an open-source sample project agora-simple-filter on GitHub for your reference.