AgoraIO-Community / Agora-Flutter-Quickstart

Quickstart guide for the Agora Flutter SDK(Android/iOS)
MIT License
506 stars 193 forks source link

can we use this example to puild Video Broadcasting #9

Closed mohammadabushalhoob closed 4 years ago

mohammadabushalhoob commented 5 years ago

hi ,

can we use this example to puild Video Broadcasting .

thank you

PRWrl commented 5 years ago

Yes,

AgoraRtcEngine.setChannelProfile(ChannelProfile.LiveBroadcasting) before join channel, and AgoraRtcEngine.setClientRole(ClientRole.Broadcaster) for broadcaster and AgoraRtcEngine.setClientRole(ClientRole.Audience) for audience.

sarthaksadh01 commented 5 years ago

does it support screen sharing ?

PRWrl commented 5 years ago

Screen sharing is not supported for mobile SDK yet, it depends ReplayKit on iOS and Media Projection on Android.

sarthaksadh01 commented 5 years ago

So is it possible to pass external video in flutter? Like i have screen sharing code in flutter which provides live video frames how to pass this to agora? thank you

 MediaStream _localStream;`
  final _localRenderer = new RTCVideoRenderer()`;
 await _localRenderer.initialize();
 final Map<String, dynamic> mediaConstraints = {
      "audio": true,
      "video": true
    };
 var stream = await navigator.getDisplayMedia(mediaConstraints);
      _localStream = stream;
      _localRenderer.srcObject = _localStream;

so is it possible to pass this _localStream for broadcasting.

using the plugin flutter_ webrtc

PRWrl commented 5 years ago

Sorry but external media source is not supported.

alfonsodev commented 5 years ago

Hello, thank you for this Flutter SDK Sample! I'm trying to make live broadcast work, here is the gist https://gist.github.com/alfonsodev/e7228253734ba11cd6cecc5cc50488f3 It is simplified to join directly to a broadcast, The Broadcaster seems to work (I can see the preview video) on the Audience side I only see black screen.

This is how I initialise the Audience side

  Future<void> _initAgoraRtcEngine() async {
    AgoraRtcEngine.create('xxxxxxxxxxxxxxxxxx');
    AgoraRtcEngine.enableVideo();
    AgoraRtcEngine.setChannelProfile(ChannelProfile.LiveBroadcasting);
    AgoraRtcEngine.setClientRole(ClientRole.Audience);
    AgoraRtcEngine.enableWebSdkInteroperability(true);
  }

And then I render with

AgoraRtcEngine.createNativeView(1, (viewId) {
  AgoraRtcEngine.setupRemoteVideo(viewId, VideoRenderMode.Fit, 1);
  AgoraRtcEngine.joinChannel(null, 'flutter', null, 1);
})

And here is how I initialise the Host side,

  Future<void> _initAgoraRtcEngine() async {
    AgoraRtcEngine.create('xxxxxxxxxxxxxxxxxxxx');
    AgoraRtcEngine.enableVideo();
    AgoraRtcEngine.setChannelProfile(ChannelProfile.LiveBroadcasting);
    AgoraRtcEngine.setClientRole(ClientRole.Broadcaster);
    AgoraRtcEngine.enableWebSdkInteroperability(true);
  }

and render

AgoraRtcEngine.createNativeView(0, (viweId) {
  AgoraRtcEngine.setupLocalVideo(viweId, VideoRenderMode.Fit);
  AgoraRtcEngine.startPreview();
  AgoraRtcEngine.joinChannel(null, 'flutter', null, 0);
})

Any ideas why I'm not getting video in the Audience side ?

Thank you ❤️

PRWrl commented 5 years ago

Hi @alfonsodev

Audience has to setupRemoteVideo with uid of broadcaster, which you can get in the onUserJoined callback.

AgoraRtcEngine.joinChannel(null, 'flutter', null, audienceUid);

AgoraRtcEngine.createNativeView(broadcasterUid, (viewId) {
  AgoraRtcEngine.setupRemoteVideo(viewId, VideoRenderMode.Fit, broadcasterUid);
})
alfonsodev commented 5 years ago

Thanks the quick reply, but onUserJoined, doesn't trigger on the Audience side

    AgoraRtcEngine.setChannelProfile(ChannelProfile.LiveBroadcasting);
    AgoraRtcEngine.setClientRole(ClientRole.Audience);
    AgoraRtcEngine.onUserJoined = (int uid, int elapsed) {
      _log("onUserJoined: uid: $uid  elapsed: $elapsed");
    };
    AgoraRtcEngine.enableVideo();
    _log('to join channel flutter with uid $_uid');

    AgoraRtcEngine.leaveChannel();
    AgoraRtcEngine.joinChannel(null, 'flutter', null, 0);

I found in the source code, onUserJoined

/// Live-broadcast profile: This callback notifies the app when the host joins the channel. If other hosts are already in the channel, the SDK also reports to the app on the existing hosts. Agora recommends having at most 17 hosts in a channel

But doesn't seem to trigger when the host joins, I'm testing on a real device, on debug mode.

update : I've added onError and I don't say any error either

alfonsodev commented 5 years ago

sorry it is working now, for some reason onUserJoined wasn't triggering but it is working. thanks!

Andresdiazz commented 5 years ago

Hello alfonsodev, in main.dart, I call the method Host.dart or Audiende.dart?

ejdrian313 commented 4 years ago

Hi @alfonsodev

Audience has to setupRemoteVideo with uid of broadcaster, which you can get in the onUserJoined callback.

AgoraRtcEngine.joinChannel(null, 'flutter', null, audienceUid);

AgoraRtcEngine.createNativeView(broadcasterUid, (viewId) {
  AgoraRtcEngine.setupRemoteVideo(viewId, VideoRenderMode.Fit, broadcasterUid);
})

could you provide full example? i still getting black screen with as a audiance

rlee1990 commented 4 years ago

I tried setting up mine the way @alfonsodev but when I try to broadcast I get a black screen. @PRWrl could you help?

plutoless commented 4 years ago

@rlee1990 please follow instructions here to report an issue.

plutoless commented 4 years ago

@rlee1990 i'll close this one. please provide details in the new ticket you just opened.

khaliqdadmohmand commented 4 years ago

Yes,

AgoraRtcEngine.setChannelProfile(ChannelProfile.LiveBroadcasting) before join channel, and AgoraRtcEngine.setClientRole(ClientRole.Broadcaster) for broadcaster and AgoraRtcEngine.setClientRole(ClientRole.Audience) for audience.

do you have any example of that ? plz i need to make a live bradcasting module in my app

plutoless commented 4 years ago

@khaliqdadmohmand is the sample within this repository not working for you?

khaliqdadmohmand commented 4 years ago

i have issue in this line..

AgoraRtcEngine.createNativeView(0, (viweId){})

where it support only one parameter.. if i remove the broadcaster or audience ID which is here 0 in example.. the code works fine but audience cannot see the breadcaster.. please help me

plutoless commented 4 years ago

sorry i don't quite get it. could you pls show me how you changed the code or share with me a sample project?