Introduction
Implement Screen Share functionality into your Flutter video call app for Android to enhance user experience and collaboration. With Screen Share, users can seamlessly share their device screens during video calls, making it easier to present documents, slideshows, or demonstrate apps. By integrating this feature, your app becomes a versatile tool for remote work, online learning, and virtual meetings. With Flutter's flexibility and powerful capabilities, you can quickly develop and deploy this feature, keeping your app at the forefront of modern communication technology.
Benefits of implementing Screen Share in your Flutter video call app for Android:
- Enhanced Collaboration: Users can collaborate effectively by sharing their screens, allowing for real-time discussions and feedback.
- Efficient Communication: Screen Share enables clearer communication by visually demonstrating ideas, documents, or presentations.
- Remote Work Facilitation: Facilitates remote work by enabling virtual meetings where team members can share progress, review documents, and provide guidance.
- Technical Support: Users can share their screens to seek technical assistance, allowing support staff to diagnose issues or guide troubleshooting steps more efficiently.
- Ease of Use: The intuitive user interface makes it easy for users to initiate screen sharing, enhancing user experience.
Use Cases Screen Share in your Flutter video call app:
- Online Meetings: Participants can share their screens to discuss reports, and presentations, or collaborate on projects.
- Remote Training: Trainers can demonstrate software usage or guide trainees through processes by sharing their screens.
- Virtual Classrooms: Educators can share educational content, conduct lectures, or provide one-on-one assistance to students.
- Software Demos: Developers or product managers can provide software demonstrations to stakeholders or users.
- Collaborative Editing: Users can collectively edit documents or work on projects by sharing their screens.
Elevate your app's capabilities and provide users with a truly immersive and productive video calling experience with screen sharing with VideoSDK.
Getting Started with VideoSDK
To take advantage of Screen Share, 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 Video SDK
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
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
an interface. Just add this to your app-level/android/app/build.gradle
.
android {
//...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
- 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 set to30
).
Essential Steps to Implement Video Calling 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 pressedonToggleMicButtonPressed
: invoked when the toggle mic button pressedonToggleCameraButtonPressed
: 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 Screen Share Feature
Screen sharing in a meeting is the process of sharing your device screen with other participants in the meeting. It allows everyone in the meeting to see exactly what you are seeing on your screen, which can be helpful for presentations, demonstrations, or collaborations.
Why Integrate Screen Sharing with VideoSDK?
Integrating screen sharing into your Flutter video calling app using VideoSDK presents several compelling reasons:
- Simplified Development: With VideoSDK, the intricate tasks of screen capture and transmission are effortlessly managed, saving you valuable development time and resources.
- Native Functionality: Harnessing the power of the Android Media Projection API, VideoSDK ensures a seamless and efficient screen-sharing experience for your users, providing them with a native feel and optimal performance.
- Seamless Integration: The integration process with VideoSDK is intuitive and hassle-free, enabling you to seamlessly incorporate screen-sharing functionality into your existing video call features without extensive modifications.
- Robust Features: VideoSDK offers a robust screen-sharing solution equipped with essential features such as permission handling and in-app sharing capabilities, guaranteeing a reliable and user-friendly experience.
By embracing screen sharing through VideoSDK, you elevate the functionality and appeal of your Flutter video-calling app, providing users with an enriched communication experience.
Enable Screen Share
- By using
enableScreenShare()
function ofRoom
object, a local participant can share his/her screen or window with other participants. - The screen share stream of the participant can be accessed from the
streams
property ofParticipant
object.
Disable Screen Share
- By using
disableScreenShare()
function ofRoom
object, a local participant can stop sharing his/her screen or window with other participants.
Events associated with Screen Share
Events associated with Enable ScreenShare
Every Participant will receive a callback on Events.streamEnabled
of the Participant
object with Stream
object.
- Every Remote Participant will receive
Events.presenterChanged
callback on theRoom
object with the participantId aspresenterId
who started the screen share.
Events associated with Disable ScreenShare
- Every Participant will receive a callback on
Events.streamDisabled
of theParticipant
object withStream
object. - Every Remote Participant will receive
Events.presenterChanged
callback on theRoom
object with thepresenterId
asnull
.
Example
To render the screenshare, you will need to know participantId
who is presenting the screen, which can be found in the presenterId
property of Room
object.
We will listen for the Events.presenterChanged
on Room
object to check if some other participant starts screen share, Events.streamEnabled
and Events.streamDisabled
on the localParticipant
's object to identify if the local participant is presenting or not.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';
import './participant_tile.dart';
import './screen_share_view.dart';
class MeetingScreen extends StatefulWidget {
final String meetingId;
final String token;
const MeetingScreen(
{super.key, required this.meetingId, required this.token});
State<MeetingScreen> createState() => _MeetingScreenState();
}
class _MeetingScreenState extends State<MeetingScreen> {
late Room _room;
var micEnabled = true;
var camEnabled = true;
String? _presenterId;
Map<String, Participant> participants = {};
void initState() {
// create room
_room = VideoSDK.createRoom(
roomId: widget.meetingId,
token: widget.token,
displayName: "John Doe",
micEnabled: micEnabled,
camEnabled: camEnabled
);
setMeetingEventListener();
// Join room
_room.join();
super.initState();
}
// listening to meeting events
void setMeetingEventListener() {
// ...
//Listening if remote participant starts presenting
_room.on(Events.presenterChanged, (String? presenterId) {
setState(() => {_presenterId = presenterId});
});
//Listening if local participant starts presenting
_room.localParticipant.on(Events.streamEnabled, (Stream stream) {
if (stream.kind == "share") {
setState(() => {_presenterId = _room.localParticipant.id});
}
});
_room.localParticipant.on(Events.streamDisabled, (Stream stream) {
if (stream.kind == "share") {
setState(() => {_presenterId = null});
}
});
}
// onbackButton pressed leave the room
Future<bool> _onWillPop() async {
_room.leave();
return true;
}
// This widget is the root of your application.
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () => _onWillPop(),
child: Scaffold(
appBar: AppBar(
title: const Text('VideoSDK QuickStart'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Text(widget.meetingId),
//render all participant
// ...
//we will render the screenshare view if the presenterId is not null
if (_presenterId != null)
ScreenShareView(
participant: _presenterId == _room.localParticipant.id
? _room.localParticipant
: _room.participants[_presenterId],
),
// MeetingControls
// ....
ElevatedButton(
onPressed: () {
if (_presenterId != null) {
_room.disableScreenShare();
} else {
_room.enableScreenShare();
}
},
child: const Text('Toggle Screnshare')),
],
),
),
),
home: JoinScreen(),
);
}
}
Now that we know if there is an active presenter, let us get the screen share stream from the Participant
object and render it.
import 'package:flutter/material.dart';
import 'package:videosdk/videosdk.dart';
class ScreenShareView extends StatelessWidget {
final Participant? participant;
ScreenShareView({super.key, required this.participant}) {
//intialize the shareStream
participant?.streams.forEach((key, value) {
if (value.kind == "share") {
shareStream = value;
}
});
}
Stream? shareStream;
Widget build(BuildContext context) {
return Container(
color: Colors.grey.shade800,
height: 300,
width: 200,
//show the screen share stream
child: shareStream != null
? RTCVideoView(
shareStream?.renderer as RTCVideoRenderer,
objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover,
)
: null,
);
}
}
Conclusion
Integrating screen sharing into your Flutter video calling app using VideoSDK offers users a powerful tool to enhance communication and collaboration. This feature is beneficial in a range of scenarios, from business presentations to technical demonstrations, making your app a versatile and valuable platform.
Leveraging VideoSDK's seamless integration capabilities, the process of incorporating screen sharing becomes not only feasible but also streamlined, enabling you to devote more attention to crafting a remarkable user interface and experience.
Unlock VideoSDK's full potential and craft seamless video experiences effortlessly. Sign up today and receive 10,000 free minutes to elevate your video app to new heights.