Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Agora Video SDK tool

INSTALL AGORA VIDEO SDK TOOL INTO FLUTTER PROJECT

Seryas It Solutions had a chance to install the Agora Video SDK tool on one of our apps. So, we just wanted to write down the steps on how to set up Agora Video SDK into a Flutter project.

Agora’s Video SDK is a tool that makes it easier to incorporate real-time video chat into native, mobile, and web applications. Without needing to have a deep understanding of video codecs, network protocols, or signal processing, it gives developers a complete set of APIs and tools to add video-calling capabilities to their apps. By enabling real-time video communication, developers can improve the user experience of their apps by integrating the Agora Video SDK.

Step 1:

Create a Agora account to get an App ID;

How to setup Agora into a flutter project

Step 2.

Set up a Flutter environment for a Video Calling project.

In the terminal, run the following command:

flutter doctor

Step 3.

Create a Flutter app and Add Video SDK into the project.

Add the following lines to pubspec.yaml under dependencies.

agora_rtc_engine: ^x.y.z

permission_handler: ^9.2.0

Step 4.

Use the Flutter framework to download dependencies to your app

flutter pub get

Step 5:

Create .env file and paste app id

AGORA_APP_ID=agora app id

Step 6:

Implement a client for Video Calling

1. Import the required Agora and Flutter libraries in /lib/main.dart

import ‘dart:async’;

import ‘package:flutter/material.dart’;

import ‘package:permission_handler/permission_handler.dart’;

import ‘package:agora_rtc_engine/agora_rtc_engine.dart’;

2. Set up the app framework

To set up a Flutter app framework.

  • Create a stateful widget
  • Declare the connection variables including the appId,channelName, and token.
  • Add a method to display information to the user
const String appId = ""; void main() => runApp(const MaterialApp(home: MyApp())); class MyApp extends StatefulWidget { const MyApp({Key? key}) : super(key: key); @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { String channelName = ""; String token = ""; int uid = 0; // uid of the local user int? _remoteUid; // uid of the remote user bool _isJoined = false; // Indicates if the local user has joined the channel late RtcEngine agoraEngine; // Agora engine instance final GlobalKey scaffoldMessengerKey = GlobalKey(); // Global key to access the scaffold showMessage(String message) { scaffoldMessengerKey.currentState?.showSnackBar(SnackBar( content: Text(message), )); } }

Implement the user interface

To implement the user interface, you create the following UI elements:

    • An AgoraVideoViewwidget to display the local video preview.
    • An AgoraVideoView widget to render the remote video.
    • A button to Join a channel.
    • A button to Leave the channel.
db.createUser( // Build UI @override Widget build(BuildContext context) { return MaterialApp( scaffoldMessengerKey: scaffoldMessengerKey, home: Scaffold( appBar: AppBar( title: const Text('Get started with Video Calling'), ), body: ListView( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4), children: [ // Container for the local video Container( height: 240, decoration: BoxDecoration(border: Border.all()), child: Center(child: _localPreview()), ), const SizedBox(height: 10), //Container for the Remote video Container( height: 240, decoration: BoxDecoration(border: Border.all()), child: Center(child: _remoteVideo()), ), // Button Row Row( children: [ Expanded( child: ElevatedButton( onPressed: _isJoined ? null : () => {join()}, child: const Text("Join"), ), ), const SizedBox(width: 10), Expanded( child: ElevatedButton( onPressed: _isJoined ? () => {leave()} : null, child: const Text("Leave"), ), ), ], ), // Button Row ends ], )), ); } // Display local video preview Widget _localPreview() { if (_isJoined) { return AgoraVideoView( controller: VideoViewController( rtcEngine: agoraEngine, canvas: VideoCanvas(uid: 0), ), ); } else { return const Text( 'Join a channel', textAlign: TextAlign.center, ); } } // Display remote user's video Widget _remoteVideo() { if (_remoteUid != null) { return AgoraVideoView( controller: VideoViewController.remote( rtcEngine: agoraEngine, canvas: VideoCanvas(uid: _remoteUid), connection: RtcConnection(channelId: channelName), ), ); } else { String msg = ''; if (_isJoined) msg = 'Waiting for a remote user to join'; return Text( msg, textAlign: TextAlign.center, ); } }

The post Agora Video SDK tool appeared first on Sreyas IT.



This post first appeared on Mobile App Development Companies In Kochi | Sreyas IT Solutions, please read the originial post: here

Share the post

Agora Video SDK tool

×

Subscribe to Mobile App Development Companies In Kochi | Sreyas It Solutions

Get updates delivered right to your inbox!

Thank you for your subscription

×