Introduction
Active speaker indication is an important feature in any video calling application, particularly during group calls. It plays a crucial role in keeping users engaged and informed about who is speaking at any given moment. This not only gives smoother communication but also reduces confusion, leading to an overall improved user experience.
In this comprehensive guide, we will understand the process of implementing active speaker indication in your Flutter video calling app using VideoSDK. Leveraging the advanced capabilities offered by VideoSDK, we will demonstrate how to accurately identify the loudest speaker in a call and seamlessly integrate visual cues within your app's interface.
Getting Started with VideoSDK
To take advantage of Active Speaker, we must use the capabilities that the VideoSDK offers. Before diving into the implementation steps, let's ensure you complete the necessary prerequisites.
Create a VideoSDK Account
Go to your VideoSDK dashboard and sign up if you don't have an account. This account gives you access to the required Video SDK token, which acts as an authentication key that allows your application to interact with VideoSDK functionality.
Generate your Auth Token
Visit your VideoSDK dashboard and navigate to the "API Key" section to generate your auth token. This token is crucial in authorizing your application to use VideoSDK features.
For a more visual understanding of the account creation and token generation process, consider referring to the provided tutorial.
Prerequisites
Before proceeding, ensure that your development environment meets the following requirements:
- Video SDK Developer Account (if you do not have one, follow VideoSDK Dashboard)
- The basic understanding of Flutter.
- Flutter VideoSDK
- Have Flutter installed on your device.
Install VideoSDK
Install the VideoSDK using the below-mentioned flutter command. Make sure you are in your Flutter app directory before you run this command.
$ flutter pub add videosdk
//run this command to add http library to perform network call to generate roomId
$ flutter pub add http
VideoSDK Compatibility
Android and iOS app | Web | Desktop app | Safari browser |
---|---|---|---|
Structure of the project
Your project structure should look like this.
root
├── android
├── ios
├── lib
├── api_call.dart
├── join_screen.dart
├── main.dart
├── meeting_controls.dart
├── meeting_screen.dart
├── participant_tile.dart
We are going to create flutter widgets (JoinScreen, MeetingScreen, MeetingControls, and ParticipantTile).
App Structure
The app widget will contain JoinScreen
and MeetingScreen
widget. MeetingScreen
will have MeetingControls
and ParticipantTile
widget.
Configure Project For Android
- Update
/android/app/src/main/AndroidManifest.xml
for the permissions we will be using to implement the audio and video features. - Also, you will need to set your build settings to Java 8 because the official WebRTC jar now uses static methods in
EglBase
the interface. Just add this to your app-level/android/app/build.gradle
. - If necessary, in the same
build.gradle
you will need to increaseminSdkVersion
ofdefaultConfig
up to23
(currently default Flutter generator set to16
). - If necessary, in the same
build.gradle
you will need to increasecompileSdkVersion
andtargetSdkVersion
up to33
(currently, the default Flutter generator sets it to30
).
android {
//...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Configure Project For iOS
- Add the following entries that allow your app to access the camera and microphone in your
/ios/Runner/Info.plist
file:
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) Camera Usage!</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) Microphone Usage!</string>
- Uncomment the following line to define a global platform for your project in
/ios/Podfile
:
# platform :ios, '12.0'
For MacOS
- Add the following entries to your
/macos/Runner/Info.plist
file that allow your app to access the camera and microphone:
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) Camera Usage!</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) Microphone Usage!</string>
- Add the following entries to your
/macos/Runner/DebugProfile.entitlements
file that allows your app to access the camera, microphone, and open outgoing network connections:
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>
<key>com.apple.security.device.microphone</key>
<true/>
- Add the following entries to your
/macos/Runner/Release.entitlements
file that allows your app to access the camera, microphone, and open outgoing network connections:
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>
<key>com.apple.security.device.microphone</key>
<true/>
Essential Steps to Implement Video Call Functionality
Before diving into the specifics of screen-sharing implementation, it's crucial to ensure you have VideoSDK properly installed and configured within your Flutter project. Refer to VideoSDK's documentation for detailed installation instructions. Once you have a functional video calling setup, you can proceed with adding the screen-sharing feature.
Step 1: Get started with api_call.dart
api_call.dart
Before jumping to anything else, you will write a function to generate a unique meetingId. You will require an authentication token, you can generate it either by using videosdk-rtc-api-server-examples or by generating it from the VideoSDK Dashboard for development.
Step 2: Creating the JoinScreen
Let's create join_screen.dart
file in lib
directory and create JoinScreen StatelessWidget
.
The JoinScreen will consist of:
- Create Meeting Button: This button will create a new meeting for you.
- Meeting ID TextField: This text field will contain the meeting ID, you want to join.
- Join Meeting Button: This button will join the meeting, which you have provided.
- Update the home screen of the app in the
main.dart
Step 3: Creating the MeetingControls
Let's create meeting_controls.dart
file and create MeetingControls StatelessWidget
.
The MeetingControls will consist of:
- Leave Button: This button will leave the meeting.
- Toggle Mic Button: This button will unmute or mute the mic.
- Toggle Camera Button: This button will enable or disable the camera.
MeetingControls will accept 3 functions in the constructor.
- onLeaveButtonPressed: invoked when the Leave button pressed
- onToggleMicButtonPressed: invoked when the toggle mic button pressed
- onToggleCameraButtonPressed: invoked when the toggle Camera button pressed
Step 4: Creating ParticipantTile
Let's create participant_tile.dart
file and create ParticipantTile StatefulWidget
.
The ParticipantTile will consist of:
- RTCVideoView: This will show the participant's video stream.
ParticipantTile will accept Participant
in constructor
- participant: participant of the meeting.
Step 5: Creating the MeetingScreen
Let's create meeting_screen.dart
file and create MeetingScreen StatefulWidget
.
MeetingScreen will accept meetingId and token in the constructor.
- meetingID: meetingId, you want to join
- token: VideoSDK Auth token.
CAUTION
If you getwebrtc/webrtc.h file not found
error at a runtime in iOS, then check the solution here.
TIP
You can checkout the complete quick start example here.
Integrate Active Speaker Indication Feature
Once you've seamlessly integrated VideoSDK into your Flutter project, you'll unlock the powerful capability of Active Speaker Indication. This innovative feature operates by gauging the audio volume of participants, dynamically discerning the speaker in real time. By implementing VideoSDK's provided guides, your application gains the ability to stay synced with levels, ensuring a seamless experience for your users.
In the following sections, we'll go through these guides, offering comprehensive guidance on their integration. By following our step-by-step instructions, you'll adeptly implement these callbacks, effectively illuminating the active speaker within your video call interface.
The active Speaker indication feature in VideoSDK lets you know, which participant in a meeting is an active speaker. This feature can be particularly useful in larger meetings or webinars, where there may be many participants and it can be difficult to tell who is speaking.
Whenever any participant speaks in a meeting, speakerChanged
the event will trigger with the participant id of the active speaker.
For example, the meeting is running with Alice and Bob. Whenever any of them speaks, speakerChanged
the event will trigger and return the speaker participantId
.
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';
class MeetingScreen extends StatefulWidget {
...
}
class _MeetingScreenState extends State<MeetingScreen> {
late Room room;
void initState() {
...
setupRoomEventListener();
}
Widget build(BuildContext context) {
return YourMeetingWidget();
}
void setupRoomEventListener() {
room.on(Events.speakerChanged, (String? activeSpeakerId) {
//Room active speaker has changed
//Participant ID of current active speaker is activeSpeakerId
});
}
}
Conclusion
By following these steps, you'll successfully integrate active speaker indication into your Flutter video-calling app, elevating its group call functionalities to new heights. Empower your users with real-time insights into the active speaker, fostering more engaging and efficient communication experiences.
Remember to refer to VideoSDK's documentation for ongoing support and updates, ensuring your app remains at the forefront of video conferencing innovation.