Skip to content

Commit 767aad3

Browse files
committed
[Android] bugfisx
1 parent bb665d8 commit 767aad3

2 files changed

Lines changed: 9 additions & 24 deletions

File tree

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@
5454
import io.agora.rtc2.video.VideoCanvas;
5555
import io.agora.rtc2.video.VideoEncoderConfiguration;
5656

57-
import java.lang.reflect.Field;
58-
import java.lang.reflect.Method;
59-
6057
/**
6158
* This example demonstrates how video can be flexibly switched between the camera stream and the
6259
* screen share stream during an audio-video call.
@@ -122,7 +119,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
122119
join.setOnClickListener(this);
123120

124121
screenPreview = view.findViewById(R.id.screen_preview);
125-
//externalMediaPro = view.findViewById(R.id.media_projection_external);
122+
externalMediaPro = view.findViewById(R.id.media_projection_external);
126123
screenAudio = view.findViewById(R.id.screen_audio);
127124
screenAudioVolume = view.findViewById(R.id.screen_audio_volume);
128125
screenScenarioType = view.findViewById(R.id.spinner_screen_scenario_type);
@@ -218,6 +215,7 @@ private void enableNotifications() {
218215

219216
@Override
220217
public void onDestroy() {
218+
stopMediaProjectionService();
221219
/*leaveChannel and Destroy the RtcEngine instance*/
222220
if (engine != null) {
223221
engine.leaveChannel();
@@ -247,23 +245,8 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
247245
}
248246
screenCaptureParameters.captureAudio = checked;
249247
engine.updateScreenCaptureParameters(screenCaptureParameters);
250-
} /*else if (compoundButton == externalMediaPro) {
251-
}*/
252-
}
253-
254-
@Override
255-
protected void onBackPressed() {
256-
joined = false;
257-
stopMediaProjectionService();
258-
/*leaveChannel and Destroy the RtcEngine instance*/
259-
if (engine != null) {
260-
engine.leaveChannel();
261-
engine.stopScreenCapture();
262-
engine.stopPreview();
248+
} else if (compoundButton == externalMediaPro) {
263249
}
264-
handler.post(RtcEngine::destroy);
265-
engine = null;
266-
super.onBackPressed();
267250
}
268251

269252
@Override
@@ -331,7 +314,7 @@ public void onResume() {
331314
}
332315

333316
private void startMediaProjectionService() {
334-
if (joined) {
317+
// if (joined) {
335318
Context context = getContext();
336319
if (context != null) {
337320
Intent intent = new Intent(context, MediaProjectionService.class);
@@ -342,7 +325,7 @@ private void startMediaProjectionService() {
342325
}
343326
}
344327
}
345-
}
328+
// }
346329

347330
private void stopMediaProjectionService() {
348331
Context context = getContext();
@@ -353,6 +336,7 @@ private void stopMediaProjectionService() {
353336
}
354337

355338
private void requestScreenCapture() {
339+
startMediaProjectionService();
356340
Intent intent = mediaProjectionManager.createScreenCaptureIntent();
357341
mediaProjectionLauncher.launch(intent);
358342
}
@@ -576,6 +560,7 @@ public void onUserOffline(int uid, int reason) {
576560

577561
private void leaveChannel() {
578562
externalMediaPro.setEnabled(true);
563+
stopMediaProjectionService();
579564
joined = false;
580565
join.setText(getString(R.string.join));
581566
fl_local.removeAllViews();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
android:layout_marginBottom="16dp"
126126
android:text="@string/screen_share_preview" />
127127

128-
<!-- <Switch
128+
<Switch
129129
android:id="@+id/media_projection_external"
130130
android:layout_width="match_parent"
131131
android:layout_height="wrap_content"
@@ -134,7 +134,7 @@
134134
android:paddingHorizontal="16dp"
135135
android:checked="false"
136136
android:enabled="true"
137-
android:text="@string/external_mediaprojection" />-->
137+
android:text="@string/external_mediaprojection" />
138138

139139

140140

0 commit comments

Comments
 (0)