Skip to content

Commit 66ec022

Browse files
author
xianing
committed
fix andoid issues
1 parent 83aacb2 commit 66ec022

9 files changed

Lines changed: 84 additions & 738 deletions

File tree

Android/APIExample/app/src/main/java/io/agora/api/example/ExampleActivity.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import io.agora.api.example.examples.advanced.ProcessRawData;
2828
import io.agora.api.example.examples.advanced.PushExternalVideo;
2929
import io.agora.api.example.examples.advanced.SendDataStream;
30-
import io.agora.api.example.examples.advanced.SetVideoProfile;
3130
import io.agora.api.example.examples.advanced.SetAudioProfile;
3231
import io.agora.api.example.examples.advanced.SimpleAudioExtension;
3332
import io.agora.api.example.examples.advanced.VideoQuickSwitch;
@@ -129,9 +128,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
129128
case R.id.action_mainFragment_to_hostacrosschannel:
130129
fragment = new HostAcrossChannel();
131130
break;
132-
case R.id.action_mainFragment_to_set_video_profile:
133-
fragment = new SetVideoProfile();
134-
break;
135131
case R.id.action_mainFragment_to_channel_encryption:
136132
fragment = new ChannelEncryption();
137133
break;

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

Lines changed: 0 additions & 520 deletions
This file was deleted.

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

Lines changed: 32 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public class SwitchCameraScreenShare extends BaseFragment implements View.OnClic
7676
private static final String TAG = SwitchCameraScreenShare.class.getSimpleName();
7777
private static final int PROJECTION_REQ_CODE = 1 << 2;
7878
private static final int DEFAULT_SHARE_FRAME_RATE = 15;
79-
private FrameLayout fl_remote;
80-
private RelativeLayout fl_local;
79+
private FrameLayout fl_camera, fl_screen;
8180
private Button join, renderMode;
8281
private Switch camera, screenShare;
8382
private EditText et_channel;
@@ -101,12 +100,11 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
101100
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
102101
super.onViewCreated(view, savedInstanceState);
103102
join = view.findViewById(R.id.btn_join);
104-
renderMode = view.findViewById(R.id.renderMode);
105103
camera = view.findViewById(R.id.camera);
106104
screenShare = view.findViewById(R.id.screenShare);
107105
et_channel = view.findViewById(R.id.et_channel);
108-
fl_remote = view.findViewById(R.id.fl_remote);
109-
fl_local = view.findViewById(R.id.fl_local);
106+
fl_camera = view.findViewById(R.id.fl_camera);
107+
fl_screen = view.findViewById(R.id.fl_screenshare);
110108
join.setOnClickListener(this);
111109
renderMode.setOnClickListener(this);
112110
camera.setOnCheckedChangeListener(this);
@@ -167,6 +165,7 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
167165
options.publishScreenTrack = true;
168166
options.publishCameraTrack = false;
169167
engine.updateChannelMediaOptions(options);
168+
addScreenSharePreview();
170169
}
171170
}
172171

@@ -266,8 +265,9 @@ public void onClick(View v) {
266265
join.setText(getString(R.string.join));
267266
camera.setEnabled(false);
268267
screenShare.setEnabled(false);
269-
fl_remote.removeAllViews();
270-
fl_local.removeAllViews();
268+
fl_camera.removeAllViews();
269+
fl_screen.removeAllViews();
270+
engine.stopPreview();
271271
/**After joining a channel, the user must call the leaveChannel method to end the
272272
* call before joining another channel. This method returns 0 if the user leaves the
273273
* channel and releases all resources related to the call. This method call is
@@ -288,21 +288,10 @@ public void onClick(View v) {
288288
engine.leaveChannel();
289289
TEXTUREVIEW = null;
290290
}
291-
} else if (v.getId() == R.id.renderMode) {
292-
if (remoteUid == -1) {
293-
return;
294-
}
295-
if (curRenderMode == RENDER_MODE_HIDDEN) {
296-
curRenderMode = RENDER_MODE_FIT;
297-
renderMode.setText(String.format(getString(R.string.rendermode), getString(R.string.fit)));
298-
} else if (curRenderMode == RENDER_MODE_FIT) {
299-
curRenderMode = RENDER_MODE_HIDDEN;
300-
renderMode.setText(String.format(getString(R.string.rendermode), getString(R.string.hidden)));
301-
}
302291
}
303292
}
304293

305-
private void addLocalPreview() {
294+
private void addScreenSharePreview() {
306295
// Check if the context is valid
307296
Context context = getContext();
308297
if (context == null) {
@@ -311,26 +300,33 @@ private void addLocalPreview() {
311300

312301
// Create render view by RtcEngine
313302
SurfaceView surfaceView = new SurfaceView(context);
314-
if (fl_local.getChildCount() > 0) {
315-
fl_local.removeAllViews();
303+
if (fl_screen.getChildCount() > 0) {
304+
fl_screen.removeAllViews();
316305
}
317306
// Add to the local container
318-
fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
307+
fl_screen.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
319308
// Setup local video to render your local camera preview
320-
engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
309+
engine.setupLocalVideo(new VideoCanvas(surfaceView, Constants.RENDER_MODE_FIT, Constants.VIDEO_MIRROR_MODE_DISABLED, Constants.VIDEO_SOURCE_SCREEN_PRIMARY, 0));
310+
engine.startPreview();
321311
}
322312

323-
private void setRemotePreview(Context context) {
324-
/**Display remote video stream*/
325-
SurfaceView remoteSurfaceView = new SurfaceView(context);
326-
remoteSurfaceView.setZOrderMediaOverlay(true);
327-
if (fl_remote.getChildCount() > 0) {
328-
fl_remote.removeAllViews();
313+
private void addCameraPreview() {
314+
// Check if the context is valid
315+
Context context = getContext();
316+
if (context == null) {
317+
return;
318+
}
319+
320+
// Create render view by RtcEngine
321+
SurfaceView surfaceView = new SurfaceView(context);
322+
if (fl_camera.getChildCount() > 0) {
323+
fl_camera.removeAllViews();
329324
}
330-
fl_remote.addView(remoteSurfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
331-
ViewGroup.LayoutParams.MATCH_PARENT));
332-
/**Setup remote video to render*/
333-
engine.setupRemoteVideo(new VideoCanvas(remoteSurfaceView, curRenderMode, remoteUid));
325+
// Add to the local container
326+
fl_camera.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
327+
// Setup local video to render your local camera preview
328+
engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
329+
// engine.startPreview();
334330
}
335331

336332
private void joinChannel(String channelId) {
@@ -382,9 +378,10 @@ private void joinChannel(String channelId) {
382378
}
383379
// Prevent repeated entry
384380
join.setEnabled(false);
381+
addCameraPreview();
382+
engine.startPreview();
385383
}
386384

387-
388385
/**
389386
* IRtcEngineEventHandler is an abstract class providing default implementation.
390387
* The SDK uses this class to report to the app on SDK runtime events.
@@ -429,7 +426,7 @@ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
429426
public void onLocalVideoStateChanged(int localVideoState, int error) {
430427
super.onLocalVideoStateChanged(localVideoState, error);
431428
if (localVideoState == 1) {
432-
Log.e(TAG, "启动成功");
429+
Log.i(TAG, "local view published successfully!");
433430
}
434431
}
435432

@@ -474,21 +471,6 @@ public void onLocalVideoStateChanged(int localVideoState, int error) {
474471
public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed) {
475472
super.onRemoteVideoStateChanged(uid, state, reason, elapsed);
476473
Log.i(TAG, "onRemoteVideoStateChanged:uid->" + uid + ", state->" + state);
477-
if (state == REMOTE_VIDEO_STATE_STARTING) {
478-
/**Check if the context is correct*/
479-
Context context = getContext();
480-
if (context == null) {
481-
return;
482-
}
483-
handler.post(() ->
484-
{
485-
remoteUid = uid;
486-
renderMode.setEnabled(true);
487-
renderMode.setText(String.format(getString(R.string.rendermode), getString(R.string.hidden)));
488-
curRenderMode = RENDER_MODE_HIDDEN;
489-
setRemotePreview(context);
490-
});
491-
}
492474
}
493475

494476
@Override
@@ -522,13 +504,6 @@ public void onUserJoined(int uid, int elapsed) {
522504
public void onUserOffline(int uid, int reason) {
523505
Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
524506
showLongToast(String.format("user %d offline! reason:%d", uid, reason));
525-
handler.post(() -> {
526-
/**Clear render view
527-
Note: The video will stay at its last frame, to completely remove it you will need to
528-
remove the SurfaceView from its parent*/
529-
engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
530-
fl_remote.removeAllViews();
531-
});
532507
}
533508
};
534509

Android/APIExample/app/src/main/res/layout/fragment_set_video_profile.xml

Lines changed: 0 additions & 95 deletions
This file was deleted.

Android/APIExample/app/src/main/res/layout/fragment_switch_camera_screenshare.xml

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,26 @@
55
android:layout_height="match_parent"
66
android:fitsSystemWindows="true"
77
tools:context=".examples.basic.JoinChannelVideo">
8-
9-
<RelativeLayout
10-
android:id="@+id/fl_local"
8+
<LinearLayout
9+
android:id="@+id/video_container"
1110
android:layout_width="match_parent"
12-
android:layout_height="match_parent"
13-
android:layout_above="@+id/ll_join" >
11+
android:layout_height="360dp"
12+
android:layout_alignParentTop="true"
13+
android:orientation="horizontal">
1414

15-
</RelativeLayout>
15+
<FrameLayout
16+
android:id="@+id/fl_camera"
17+
android:layout_width="0dp"
18+
android:layout_weight="0.5"
19+
android:layout_height="match_parent"/>
1620

17-
<FrameLayout
18-
android:id="@+id/fl_remote"
19-
android:layout_width="180dp"
20-
android:layout_height="240dp"
21-
android:layout_alignParentEnd="true" />
21+
<FrameLayout
22+
android:id="@+id/fl_screenshare"
23+
android:layout_width="0dp"
24+
android:layout_weight="0.5"
25+
android:layout_height="match_parent" />
26+
27+
</LinearLayout>
2228

2329
<LinearLayout
2430
android:id="@+id/ll_join"
@@ -52,7 +58,7 @@
5258
android:layout_alignParentEnd="true"
5359
android:layout_marginBottom="24dp"
5460
android:enabled="false"
55-
android:text="Screen Share" />
61+
android:text="@string/screen_share" />
5662

5763
<Switch
5864
android:id="@+id/camera"
@@ -61,19 +67,7 @@
6167
android:layout_above="@id/screenShare"
6268
android:layout_alignParentEnd="true"
6369
android:layout_marginBottom="24dp"
64-
android:editable="true"
6570
android:enabled="false"
6671
android:text="@string/camera" />
6772

68-
<androidx.appcompat.widget.AppCompatButton
69-
android:id="@+id/renderMode"
70-
android:layout_width="wrap_content"
71-
android:layout_height="wrap_content"
72-
android:layout_above="@id/camera"
73-
android:layout_alignParentEnd="true"
74-
android:layout_marginBottom="24dp"
75-
android:enabled="false"
76-
android:visibility="gone"
77-
android:text="@string/rendermode" />
78-
7973
</RelativeLayout>

Android/APIExample/app/src/main/res/navigation/nav_graph.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@
7474
<action
7575
android:id="@+id/action_mainFragment_to_hostacrosschannel"
7676
app:destination="@id/hostAcrossChannel" />
77-
<action
78-
android:id="@+id/action_mainFragment_to_set_video_profile"
79-
app:destination="@id/SetVideoProfile" />
8077
<action
8178
android:id="@+id/action_mainFragment_to_channel_encryption"
8279
app:destination="@id/ChannelEncryption" />
@@ -200,11 +197,6 @@
200197
android:name="io.agora.api.example.examples.advanced.HostAcrossChannel"
201198
android:label="HostAcrossChannel"
202199
tools:layout="@layout/fragment_host_across_channel" />
203-
<fragment
204-
android:id="@+id/SetVideoProfile"
205-
android:name="io.agora.api.example.examples.advanced.SetVideoProfile"
206-
android:label="SetVideoProfile"
207-
tools:layout="@layout/fragment_set_video_profile" />
208200
<fragment
209201
android:id="@+id/ChannelEncryption"
210202
android:name="io.agora.api.example.examples.advanced.ChannelEncryption"

0 commit comments

Comments
 (0)