Skip to content

Commit 0d9c601

Browse files
author
xianing
committed
support switch camera on SuperResolution
1 parent 5d60763 commit 0d9c601

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class SuperResolution extends BaseFragment implements View.OnClickListene
5050
private static final String TAG = SuperResolution.class.getSimpleName();
5151

5252
private FrameLayout fl_local, fl_remote;
53-
private Button join, btnSuperResolution;
53+
private Button join, btnSuperResolution, switchCamera;
5454
private EditText et_channel;
5555
private RtcEngine engine;
5656
private int myUid;
@@ -73,9 +73,12 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
7373
join = view.findViewById(R.id.btn_join);
7474
btnSuperResolution = view.findViewById(R.id.btn_super_resolution);
7575
btnSuperResolution.setEnabled(false);
76+
switchCamera = view.findViewById(R.id.btn_switch);
77+
switchCamera.setEnabled(false);
7678
et_channel = view.findViewById(R.id.et_channel);
7779
view.findViewById(R.id.btn_join).setOnClickListener(this);
7880
view.findViewById(R.id.btn_super_resolution).setOnClickListener(this);
81+
view.findViewById(R.id.btn_switch).setOnClickListener(this);
7982
fl_local = view.findViewById(R.id.fl_local);
8083
fl_remote = view.findViewById(R.id.fl_remote);
8184
}
@@ -172,7 +175,13 @@ public void onClick(View v)
172175
}
173176
}
174177
else if(v.getId() == R.id.btn_super_resolution){
175-
engine.enableRemoteSuperResolution(remoteUid, !enableSuperResolution);
178+
int ret = engine.enableRemoteSuperResolution(remoteUid, !enableSuperResolution);
179+
if(ret!=0){
180+
Log.w(TAG, String.format("onWarning code %d ", ret));
181+
}
182+
}
183+
else if(v.getId() == R.id.btn_switch){
184+
engine.switchCamera();
176185
}
177186
}
178187

@@ -259,6 +268,7 @@ private void joinChannel(String channelId)
259268
public void onWarning(int warn)
260269
{
261270
Log.w(TAG, String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
271+
showAlert(String.format("onWarning code %d message %s", warn, RtcEngine.getErrorDescription(warn)));
262272
}
263273

264274
/**Reports an error during SDK runtime.
@@ -421,6 +431,7 @@ public void onUserJoined(int uid, int elapsed)
421431
engine.setupRemoteVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, uid));
422432
remoteUid = uid;
423433
btnSuperResolution.setEnabled(true);
434+
switchCamera.setEnabled(true);
424435
});
425436
}
426437

@@ -447,6 +458,7 @@ public void run() {
447458
remove the SurfaceView from its parent*/
448459
engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
449460
btnSuperResolution.setEnabled(false);
461+
switchCamera.setEnabled(false);
450462
}
451463
});
452464
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@
4545
android:enabled="false"/>
4646
</LinearLayout>
4747

48+
49+
<LinearLayout
50+
android:layout_width="wrap_content"
51+
android:layout_height="40dp"
52+
android:layout_marginBottom="102dp"
53+
android:layout_marginEnd="16dp"
54+
android:layout_alignParentEnd="true"
55+
android:layout_alignParentBottom="true">
56+
<androidx.appcompat.widget.AppCompatButton
57+
android:id="@+id/btn_switch"
58+
android:layout_width="wrap_content"
59+
android:layout_height="wrap_content"
60+
android:text="@string/switch_camera"
61+
android:enabled="false"/>
62+
</LinearLayout>
63+
4864
<LinearLayout
4965
android:id="@+id/ll_join"
5066
android:layout_width="match_parent"

Android/APIExample/app/src/main/res/values-zh/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,5 @@
181181
<string name="skin_protect">肤色保护</string>
182182
<string name="item_ScreenShare">屏幕共享</string>
183183
<string name="virtual_background">虚拟背景</string>
184+
<string name="switch_camera">摄像头切换</string>
184185
</resources>

Android/APIExample/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,5 @@
185185
<string name="skin_protect">Skin Protect</string>
186186
<string name="item_ScreenShare">Screen Share</string>
187187
<string name="virtual_background">Virtual Background</string>
188+
<string name="switch_camera">switch camera</string>
188189
</resources>

0 commit comments

Comments
 (0)