我正在使用官方的flutter agora示例进行视频通话,但本地摄像头只打开,而远程用户从未被调用。
套餐: “agora_rtc_engine:^4.2.0” “权限处理程序:^8.3.0”
这是官方的例子 https://pub.dev/packages/agora_rtc_engine/example
我也在关注这个教程 https://www.youtube.com/watch?v=zVqs1EIpVxs
这是我的代码
import 'dart:async';
import 'package:agora_rtc_engine/rtc_engine.dart';
import 'package:agora_rtc_engine/rtc_local_view.dart' as RtcLocalView;
import 'package:agora_rtc_engine/rtc_remote_view.dart' as RtcRemoteView;
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
const appId = "843b5a8f8c3a4e0fbe2c804654f4ce36";
const token = "006843b5a8f8c3a4e0fbe2c804654f4ce36IAA4Le0bHwiNWScQ3+1c4sM+UXErd0xfOdjuoZRe1Dz8B9vEKrAAAAAAEADVz7HmNwPgYQEAAQAWA+Bh";
void main() => runApp(MaterialApp(home: MyApp()));
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int? _remoteUid;
bool _localUserJoined = false;
late RtcEngine _engine;
@override
void initState() {
super.initState();
initAgora();
}
Future<void> initAgora() async {
// retrieve permissions
await [Permission.microphone, Permission.camera].request();
//create the engine
_engine = await RtcEngine.create(appId);
await _engine.enableVideo();
_engine.setEventHandler(
RtcEngineEventHandler(
joinChannelSuccess: (String channel, int uid, int elapsed) {
print("local user $uid joined");
setState(() {
_localUserJoined = true;
});
},
userJoined: (int uid, int elapsed) {
print("remote user $uid joined");
setState(() {
_remoteUid = uid;
});
},
userOffline: (int uid, UserOfflineReason reason) {
print("remote user $uid left channel");
setState(() {
_remoteUid = null;
});
},
),
);
await _engine.joinChannel(token, "test_video_call", null, 0);
}
// Create UI with local view and remote view
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Agora Video Call'),
),
body: Stack(
children: [
Center(
child: _remoteVideo(),
),
Align(
alignment: Alignment.topLeft,
child: Container(
width: 100,
height: 150,
child: Center(
child: _localUserJoined
? RtcLocalView.SurfaceView()
: CircularProgressIndicator(),
),
),
),
],
),
);
}
// Display remote user's video
Widget _remoteVideo() {
if (_remoteUid != null) {
return RtcRemoteView.SurfaceView(uid: _remoteUid!);
} else {
return Text(
'Please wait for remote user to join',
textAlign: TextAlign.center,
);
}
}
}
我还浏览了插件中提供的示例代码
example
,但您需要做的事情很少ensure
。
UID
每个用户应该不同(如果测试则输入 0)token
应该与 create 方法中使用的 AppId
相同。 (如果启用了令牌)Token
将于 24 hours
到期,因此请确保令牌正常工作。Channel name
应该是unique
这里的 Github 链接是使用 Firebase 和自定义 UI 的 Agora SDK 的完整示例
特点:-
这里是中等文章链接
这是 Github 存储库链接