Skip to content

Instantly share code, notes, and snippets.

@alfonsodev
Created May 11, 2019 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save alfonsodev/e7228253734ba11cd6cecc5cc50488f3 to your computer and use it in GitHub Desktop.
Save alfonsodev/e7228253734ba11cd6cecc5cc50488f3 to your computer and use it in GitHub Desktop.
flutter Agora.io broadcast
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:permission_handler/permission_handler.dart';
import 'package:agora_rtc_engine/agora_rtc_engine.dart';
class Audience extends StatefulWidget {
@override
_AudienceState createState() => _AudienceState();
}
class _AudienceState extends State<Audience> {
static TextStyle textStyle = TextStyle(fontSize: 18, color: Colors.blue);
@override
void initState() {
super.initState();
_handleCameraAndMicPermissions();
_initAgoraRtcEngine();
}
_handleCameraAndMicPermissions() async {
await PermissionHandler().requestPermissions(
[PermissionGroup.camera, PermissionGroup.microphone]);
}
Future<void> _initAgoraRtcEngine() async {
AgoraRtcEngine.create('xxxxxxxxxxxxxxxxxxxxxxxxx');
AgoraRtcEngine.enableVideo();
AgoraRtcEngine.setChannelProfile(ChannelProfile.LiveBroadcasting);
AgoraRtcEngine.setClientRole(ClientRole.Audience);
AgoraRtcEngine.enableWebSdkInteroperability(true);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
child: Column(
children: [
Container(
height: MediaQuery.of(context).size.height - 120,
child: AgoraRtcEngine.createNativeView(1, (viewId) {
AgoraRtcEngine.setupRemoteVideo(
viewId, VideoRenderMode.Fit, 1);
AgoraRtcEngine.joinChannel(null, 'flutter', null, 1);
}),
),
],
),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:permission_handler/permission_handler.dart';
import 'package:agora_rtc_engine/agora_rtc_engine.dart';
class Host extends StatefulWidget {
@override
_HostState createState() => _HostState();
}
class _HostState extends State<Host> {
static TextStyle textStyle = TextStyle(fontSize: 18, color: Colors.blue);
@override
void initState() {
super.initState();
_handleCameraAndMicPermissions();
_initAgoraRtcEngine();
}
_handleCameraAndMicPermissions() async {
await PermissionHandler().requestPermissions(
[PermissionGroup.camera, PermissionGroup.microphone]);
}
Future<void> _initAgoraRtcEngine() async {
AgoraRtcEngine.create('xxxxxxxxxxxxxxxxxxxxx');
AgoraRtcEngine.enableVideo();
AgoraRtcEngine.setChannelProfile(ChannelProfile.LiveBroadcasting);
AgoraRtcEngine.setClientRole(ClientRole.Broadcaster);
AgoraRtcEngine.enableWebSdkInteroperability(true);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
child: Column(
children: [
Container(
height: MediaQuery.of(context).size.height - 120,
child: AgoraRtcEngine.createNativeView(0, (viweId) {
AgoraRtcEngine.setupLocalVideo(viweId, VideoRenderMode.Fit);
AgoraRtcEngine.startPreview();
AgoraRtcEngine.joinChannel(null, 'flutter', null, 0);
}),
),
],
),
),
),
);
}
}
@khaliqdadmohmand
Copy link

Hello Bro!
I need your come code for live bradcasting. can you please help me i need to create a live streaming module in my app.

@mulieriq
Copy link

mulieriq commented May 9, 2020

is AgoraRtcEngine.create('xxxxxxxxxxxxxxxxxxxxx'); for adding the channel name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment