AgoraIO-Extensions / Agora-Flutter-SDK

Flutter plugin of Agora RTC SDK for Android/iOS/macOS/Windows
https://pub.dev/packages/agora_rtc_engine
MIT License
733 stars 381 forks source link

Android/iOS - Screen Share, audio is not being shared on version 6.2.3 onwards #1432

Closed bhavinb98 closed 6 months ago

bhavinb98 commented 10 months ago

It works fine on 6.2.2. After updating the plugin, the device audio is not being shared anymore. Flutter version - 3.13.9

Screen Share Start Method -

void startScreenShare({captureAudio = true}) async {
    // Only 1 stream can be published at a time, so we mute video when sharing screen
    videoMute();

    await _engine.startScreenCapture(ScreenCaptureParameters2(
        captureAudio: captureAudio, captureVideo: true));

    _showRPSystemBroadcastPickerViewIfNeed();

    isSelfScreenShared = true;

    await _updateChannelMediaOptions(isSelfScreenShared);

    setScreenShareStatus(
        isSharingScreen: isSelfScreenShared, uid: user!.id!, self: true);
  }

Screen Share Stop Method -

void stopScreenShare() async {
    await _engine.stopScreenCapture();

    isSelfScreenShared = false;

    await _updateChannelMediaOptions(isSelfScreenShared);

    setScreenShareStatus(
        isSharingScreen: isSelfScreenShared, uid: user!.id!, self: true);
  }

Update Media Options Method -

Future<void> _updateChannelMediaOptions(bool isScreenBeingShared) async {
    await _engine.updateChannelMediaOptionsEx(
      options: ChannelMediaOptions(
        publishMicrophoneTrack: true,
        publishCameraTrack: !isScreenBeingShared,
        publishScreenTrack: isScreenBeingShared,
        publishSecondaryScreenTrack: isScreenBeingShared,
        publishScreenCaptureAudio: isScreenBeingShared,
        publishScreenCaptureVideo: isScreenBeingShared,
        clientRoleType: ClientRoleType.clientRoleBroadcaster,
      ),
      connection:
          RtcConnection(channelId: circle!.channelName!, localUid: user!.id!),
    );
  }
littleGnAl commented 10 months ago

As I know captureAudio can only capture the system audio, Is your test case is same?

bhavinb98 commented 10 months ago

Yes.

One of my use-case - share a video from phone on screen share.

The audio cannot be heard by other people and its also not available in the recording from Agora.

littleGnAl commented 10 months ago

Does the audio from the system (include system APPs) or other third-party APPs?

bhavinb98 commented 10 months ago

The YouTube app is one of the primary sources, other sources could be inbuilt media players, or 3rd party media players like VLC. Playing a video on a web browser is also used sometimes.

littleGnAl commented 10 months ago

The YouTube app is one of the primary sources, other sources could be inbuilt media players, or 3rd party media players like VLC. Playing a video on a web browser is also used sometimes.

Does this issue occur on both Android/iOS? Can you share the configuration of the devices?

There are some limitations in some devices. https://api-ref.agora.io/en/voice-sdk/flutter/6.x/API/class_screencaptureparameters2.html#class_screencaptureparameters2__parameters

bhavinb98 commented 10 months ago

Tested on Android API 33 emulator, as well as Motorola phones running Android 12.

Will test on iOS and update

bhavinb98 commented 7 months ago

I have upgraded to Android 14, API 34. Flutter version 3.19.3 Using agora plugin version 6.3.0. I have noticed the same issue. No captured audio.

I have added these permissions in my AndroidManifest.xml

<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
bhavinb98 commented 6 months ago

@littleGnAl I might've found the issue.

I have to manually call the engine.muteLocalAudioStream(false); after starting screen share. This behaviour wasn't there in 6.2.2.

But it should automatically publish because of the channel media options I am setting here -

await _engine.updateChannelMediaOptionsEx(
    options: ChannelMediaOptions(
      publishMicrophoneTrack: true,
      publishCameraTrack: !isScreenBeingShared,
      publishScreenTrack: isScreenBeingShared,
      publishSecondaryScreenTrack: isScreenBeingShared,
      publishScreenCaptureAudio: isScreenBeingShared,    // This part here is true when screen share starts
      publishScreenCaptureVideo: isScreenBeingShared,
      clientRoleType: ClientRoleType.clientRoleBroadcaster,
    ),

Another question I have is, are the screen capture audio track and the microphone audio track same?

littleGnAl commented 6 months ago

I think it may be a bug on 6.2.2, if the audio has been muted, there's nothing to publish.

github-actions[bot] commented 5 months ago

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.