Agora-Flutter-SDK
Agora-Flutter-SDK copied to clipboard
荣耀x10 鸿蒙2.0 每次打开app 开启本地预览第一次是黑屏, 后面就可以看到预览了
// 初始化应用
Future<void> initPlatformState() async {
if (defaultTargetPlatform == TargetPlatform.android) {
await [Permission.microphone, Permission.camera].request();
}
var APP_ID = Constant.agoraAppId;
// 创建 RTC 客户端实例
RtcEngineContext context = RtcEngineContext(APP_ID);
var engine = await RtcEngine.createWithContext(context);
// 开启视频
await engine.setChannelProfile(ChannelProfile.LiveBroadcasting);
await engine.enableDualStreamMode(true);
await engine.enableVideo();
await engine.enableAudio();
var config =VideoEncoderConfiguration(
dimensions: VideoDimensions(width: 720,height: 1280),
frameRate: VideoFrameRate.Fps24,
bitrate: 0,
orientationMode:VideoOutputOrientationMode.Adaptative
);
await engine.setVideoEncoderConfiguration(config);
await rtc_startPush(engine);
await rtcstartPreView(engine);
}
Future<void> rtc_startPush(RtcEngine rtcEngine) async{
await rtcEngine.muteLocalAudioStream(false);
await rtcEngine.muteAllRemoteAudioStreams(false);
await rtcEngine.muteAllRemoteVideoStreams(false);
await rtcEngine.setClientRole(ClientRole.Broadcaster);
}
Future<void> rtcstartPreView(RtcEngine rtcEngine) async{
await rtcEngine.startPreview();
}
Try show the SurfaceView/TextureView after rtcEngine.startPreview()
能给代码示例么
Here's the example:
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late final RtcEngine _engine;
bool _isReadyForReview = false;
...
@override
void initState() {
super.initState();
_init();
}
void _init() async {
_engine =
await RtcEngine.createWithContext(RtcEngineContext("<YOUR_APP_ID>"));
...
await _engine.startPreview();
setState(() {
_isReadyForReview = true;
});
}
@override
Widget build(BuildContext context) {
if (!_isReadyForReview) return Container();
...
}
}
谢谢
Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please raise a new issue.