@@ -52,7 +52,7 @@ public class MultiProcess extends BaseFragment implements View.OnClickListener
5252 private static final String TAG = MultiProcess .class .getSimpleName ();
5353 private static final Integer SCREEN_SHARE_UID = 10000 ;
5454
55- private FrameLayout fl_local ;
55+ private FrameLayout fl_local , fl_remote ;
5656 private Button join , screenShare ;
5757 private EditText et_channel ;
5858 private RtcEngine engine ;
@@ -78,8 +78,7 @@ public void onTokenWillExpire() {
7878 @ Override
7979 public View onCreateView (@ NonNull LayoutInflater inflater , @ Nullable ViewGroup container , @ Nullable Bundle savedInstanceState )
8080 {
81- View view = inflater .inflate (R .layout .fragment_two_process_screen_share , container , false );
82- return view ;
81+ return inflater .inflate (R .layout .fragment_two_process_screen_share , container , false );
8382 }
8483
8584 @ Override
@@ -93,6 +92,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
9392 view .findViewById (R .id .btn_join ).setOnClickListener (this );
9493 view .findViewById (R .id .screenShare ).setOnClickListener (this );
9594 fl_local = view .findViewById (R .id .fl_local );
95+ fl_remote = view .findViewById (R .id .fl_remote );
9696 }
9797
9898 @ Override
@@ -191,9 +191,8 @@ public void onClick(View v)
191191 * triggers the removeInjectStreamUrl method.*/
192192 engine .leaveChannel ();
193193 join .setText (getString (R .string .join ));
194- if (isSharing ) {
194+ if (isSharing )
195195 mSSClient .stop (getContext ());
196- }
197196 screenShare .setText (getResources ().getString (R .string .screenshare ));
198197 screenShare .setEnabled (false );
199198 isSharing = false ;
@@ -245,7 +244,6 @@ private void joinChannel(String channelId)
245244 fl_local .addView (surfaceView , new FrameLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT ));
246245 // Setup local video to render your local camera preview
247246 engine .setupLocalVideo (new VideoCanvas (surfaceView , RENDER_MODE_HIDDEN , 0 ));
248- // Set audio route to microPhone
249247
250248 /** Sets the channel profile of the Agora RtcEngine.
251249 CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
@@ -448,6 +446,32 @@ public void onUserJoined(int uid, int elapsed)
448446 super .onUserJoined (uid , elapsed );
449447 Log .i (TAG , "onUserJoined->" + uid );
450448 showLongToast (String .format ("user %d joined!" , uid ));
449+ // don't render screen sharing view
450+ if (SCREEN_SHARE_UID == uid ){
451+ return ;
452+ }
453+ /**Check if the context is correct*/
454+ Context context = getContext ();
455+ if (context == null ) {
456+ return ;
457+ }
458+ handler .post (() ->
459+ {
460+ /**Display remote video stream*/
461+ SurfaceView surfaceView = null ;
462+ if (fl_remote .getChildCount () > 0 )
463+ {
464+ fl_remote .removeAllViews ();
465+ }
466+ // Create render view by RtcEngine
467+ surfaceView = RtcEngine .CreateRendererView (context );
468+ surfaceView .setZOrderMediaOverlay (true );
469+ // Add to the remote container
470+ fl_remote .addView (surfaceView , new FrameLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT ));
471+
472+ // Setup remote video to render
473+ engine .setupRemoteVideo (new VideoCanvas (surfaceView , RENDER_MODE_HIDDEN , uid ));
474+ });
451475 }
452476
453477 /**Occurs when a remote user (Communication)/host (Live Broadcast) leaves the channel.
0 commit comments