Gab*_*y10 3 android ios dart flutter
我正在尝试集成Agora SDK,我已经能够将其设置为功能,但唯一的问题是本地视图是空白的,直到我进行热重启,热重启后一切功能正常,远程视图可以正常工作完美的是,我一直在尝试调试这个问题,但没有成功,下面是我的代码。
导入'dart:异步';
导入“包:flutter/material.dart”;
导入“包:permission_handler/permission_handler.dart”;
导入 'package:agora_rtc_engine/rtc_engine.dart';
导入 'package:agora_rtc_engine/rtc_local_view.dart' 作为 RtcLocalView;
导入 'package:agora_rtc_engine/rtc_remote_view.dart' 作为 RtcRemoteView;
const appId = "e660ebb529e34d838fedc01ed1a1b5e4";
常量标记 =
“006e660ebb529e34d838fedc01ed1a1b5e4IABB69OL6buUPHAgM4dq+hpsHKMLCooStMhXyvSdauF2eNzDPrsAAAAAAEADHF4BY49MwYQEAAQDi0zBh”;
void main() => runApp(MaterialApp(home: MyApp()));
类 MyApp 扩展 StatefulWidget {
@覆盖
_MyAppState createState() => _MyAppState();
}
类 _MyAppState 扩展状态 {
int _remoteUid;
RtcEngine_engine;
@覆盖
无效初始化状态(){
super.initState();
初始化声网();
}
未来 initAgora() 异步 {
// 检索权限
等待 [Permission.microphone, Permission.camera].request();
//创建引擎
_engine = 等待 RtcEngine.create(appId);
等待_engine.enableVideo();
_engine.setEventHandler(
RtcEngineEventHandler(
joinChannelSuccess: (字符串频道, int uid, int elapsed) {
print("本地用户$uid加入");
},
userJoined: (int uid, int elapsed) {
print("远程用户$uid加入");
设置状态((){
_remoteUid = uid;
});
},
userOffline: (int uid, UserOfflineReason 原因) {
print("远程用户$uid左声道");
设置状态((){
_remoteUid = null;
});
},
),
);
等待 _engine.joinChannel(token, "firstchannel", null, 0);
}
// 创建具有本地视图和远程视图的 UI
@覆盖
小部件构建(BuildContext上下文){
返回脚手架(
应用栏:应用栏(
title: const Text('声网视频通话'),
),
主体:堆栈(
孩子们: [
中心(
子:_remoteVideo(),
),
对齐(
对齐:Alignment.topLeft,
子项:容器(
宽度:100,
高度:100,
孩子:中心(
子:RtcLocalView.SurfaceView(),
),
),
),
],
),
);
}
小部件_renderLocalPreview() {
返回 RtcLocalView.SurfaceView();
}
// 显示远程用户的视频
小部件_remoteVideo() {
如果(_remoteUid!= null){
返回 RtcRemoteView.SurfaceView(uid: _remoteUid);
} 别的 {
返回文本(
'请等待远程用户加入',
文本对齐:文本对齐.center,
);
}
}
}
在与这个问题斗争了一段时间后,我意识到问题出在哪里。我需要包含一个布尔变量来检查本地用户是否已加入频道,然后再尝试显示本地预览。显然,Agora SDK 设计为仅当用户加入频道时才显示本地预览。
Widget _renderLocalPreview() {
if (_localUserJoined) {
return RtcLocalView.SurfaceView();
} else {
return Text(
'Joining Channel, Please wait.....',
textAlign: TextAlign.center,
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2871 次 |
| 最近记录: |