Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

khaliqdadmohmand commented May 8, 2020

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.

@EricRootLee
Copy link

EricRootLee 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