Created
May 11, 2019 09:39
-
-
Save alfonsodev/e7228253734ba11cd6cecc5cc50488f3 to your computer and use it in GitHub Desktop.
flutter Agora.io broadcast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is AgoraRtcEngine.create('xxxxxxxxxxxxxxxxxxxxx'); for adding the channel name?