Agora-Flutter-SDK icon indicating copy to clipboard operation
Agora-Flutter-SDK copied to clipboard

荣耀x10 鸿蒙2.0 每次打开app 开启本地预览第一次是黑屏, 后面就可以看到预览了

Open QiuYeHong90 opened this issue 3 years ago • 4 comments

  // 初始化应用
  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();
  }

QiuYeHong90 avatar Aug 03 '22 08:08 QiuYeHong90

Try show the SurfaceView/TextureView after rtcEngine.startPreview()

littleGnAl avatar Aug 05 '22 11:08 littleGnAl

能给代码示例么

QiuYeHong90 avatar Aug 08 '22 05:08 QiuYeHong90

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();
    ...
  }
}

littleGnAl avatar Aug 09 '22 10:08 littleGnAl

谢谢

QiuYeHong90 avatar Aug 10 '22 10:08 QiuYeHong90

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.

github-actions[bot] avatar Sep 05 '22 06:09 github-actions[bot]

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.

github-actions[bot] avatar Apr 28 '23 11:04 github-actions[bot]