Skip to content

Commit 825f9d9

Browse files
author
xia ning
authored
Merge pull request #220 from oOJohn6Oo/dev/3.5.1
[BGF] For MultiProcess.java enable audio&video feature and a crash fixed.
2 parents 127bb61 + 5c72c18 commit 825f9d9

2 files changed

Lines changed: 32 additions & 8 deletions

File tree

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/MultiProcess.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

Android/APIExample/lib-screensharing/src/main/java/io/agora/rtc/ss/ScreenSharingClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static ScreenSharingClient getInstance() {
3535
return mInstance;
3636
}
3737

38-
private ServiceConnection mScreenShareConn = new ServiceConnection() {
38+
private final ServiceConnection mScreenShareConn = new ServiceConnection() {
3939
public void onServiceConnected(ComponentName className, IBinder service) {
4040
mScreenShareSvc = IScreenSharing.Stub.asInterface(service);
4141

@@ -54,7 +54,7 @@ public void onServiceDisconnected(ComponentName className) {
5454
}
5555
};
5656

57-
private INotification mNotification = new INotification.Stub() {
57+
private final INotification mNotification = new INotification.Stub() {
5858
/**
5959
* This is called by the remote service to tell us about error happened.
6060
* Note that IPC calls are dispatched through a thread

0 commit comments

Comments
 (0)