S.M. Turag
S.M. Turag

Reputation: 1

How I solve the agora audion room black screen problem?

I am generate code backend in laravel and passing this code to flutter. In flutter using this code user can join audion call group. but the problem is while user take sit on the group this time the UI getting turns into black screen. So sometime remote user see the black screen and sometimes maind users.

this is my code example in flutter

socket.on('join-mic', (data) async {
          debugPrint('data: $data');

          // Retrieve the stored mic index from SharedPreferences
          SharedPreferences prefs = await SharedPreferences.getInstance();
          int? storedIndex = prefs.getInt('selectedMicIndex');

          if ("${data['groupId']}" == "${widget.id}") {
            final userData = data['user'];
            final userName = userData['name'] ?? 'Unknown User';
            final userImage = userData['image'] as String?;
            final userId = userData['id'].toString();
            final micId = int.parse(data['micId'].toString());

            if (mounted) {
              // If storedIndex is available, use it; otherwise, use micId
              int finalIndex = storedIndex ?? micId;
              print('finalIndex: $finalIndex');
              print('userId: $userId');
              print('userName: $userName');

              // If it's the current user, take the seat using storedIndex
              await _roomProvider.takeSeat(finalIndex, int.parse(userId),
                  userName: userName, userImag: userImage.toString());

              // Update UI for all users
              _roomProvider.handleUserJoinedMic(
                userId: userId,
                userName: userName,
                userImage: userImage,
                micId: finalIndex,
              );
            }
          }
        });

    Future<void> initializeSDK(String appId) async {
        if (_isSDKInitialized) return;

        try {
          // Request permissions
          final status = await Permission.microphone.request();
          if (status != PermissionStatus.granted) {
            throw Exception('Microphone permission denied');
          }

          // Create and initialize the RTC engine
          _engine = createAgoraRtcEngine();
          await _engine.initialize(RtcEngineContext(
            appId: appId,
            channelProfile: ChannelProfileType.channelProfileLiveBroadcasting,
          ));

          // Configure audio settings
          await _engine.setAudioProfile(
            profile: AudioProfileType.audioProfileDefault,
            scenario: AudioScenarioType.audioScenarioChatroom,
          );

          // Enable audio management
          await _engine.enableAudioVolumeIndication(
            interval: 200,
            smooth: 3,
            reportVad: true,
          );

          // Set up event handlers
          _setupEventHandlers();

          _isSDKInitialized = true;
          notifyListeners();
        } catch (e) {
          _handleError('Failed to initialize Agora SDK: $e');
          rethrow;
        }
      }

      // Update the initializeAgoraEngine method to use initializeSDK
      Future<void> initializeAgoraEngine(String appId) async {
        try {
          await initializeSDK(appId);
          isInitialized = true;
          notifyListeners();
        } catch (e) {
          _handleError('Failed to initialize Agora engine: $e');
        }
      }

Upvotes: 0

Views: 23

Answers (0)

Related Questions