Skip to content

Commit 9fb3d50

Browse files
committed
[Android][Screen]fix screen render bug
1 parent 11079c3 commit 9fb3d50

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.agora.api.example.examples.advanced;
22

33
import static android.app.Activity.RESULT_OK;
4-
import static io.agora.api.example.common.Constant.TEXTUREVIEW;
54
import static io.agora.api.example.common.model.Examples.ADVANCED;
65
import static io.agora.rtc2.video.VideoCanvas.RENDER_MODE_HIDDEN;
76
import static io.agora.rtc2.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
@@ -26,7 +25,6 @@
2625
import android.util.Log;
2726
import android.view.LayoutInflater;
2827
import android.view.SurfaceView;
29-
import android.view.TextureView;
3028
import android.view.View;
3129
import android.view.ViewGroup;
3230
import android.widget.Button;
@@ -174,7 +172,6 @@ public void onDestroy() {
174172
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
175173
getActivity().stopService(fgServiceIntent);
176174
}
177-
TEXTUREVIEW = null;
178175
/**leaveChannel and Destroy the RtcEngine instance*/
179176
if (engine != null) {
180177
if(camera.isChecked()){
@@ -208,13 +205,11 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
208205
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
209206
getActivity().stopService(fgServiceIntent);
210207
}
208+
options.publishScreenTrack = false;
209+
engine.updateChannelMediaOptions(options);
211210
}
212211
screenSharePreview.setEnabled(b);
213212
screenSharePreview.setChecked(b);
214-
handler.postDelayed(() -> {
215-
options.publishScreenTrack = b;
216-
engine.updateChannelMediaOptions(options);
217-
}, 1000);
218213
} else {
219214
showAlert(getString(R.string.lowversiontip));
220215
}
@@ -243,6 +238,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
243238
if(b){
244239
addScreenSharePreview();
245240
}else{
241+
fl_screen.removeAllViews();
246242
engine.stopPreview(Constants.VideoSourceType.VIDEO_SOURCE_SCREEN_PRIMARY);
247243
}
248244
}
@@ -253,8 +249,6 @@ public void onClick(View v) {
253249
if (v.getId() == R.id.btn_join) {
254250
if (!joined) {
255251
CommonUtil.hideInputBoard(getActivity(), et_channel);
256-
/**Instantiate the view ready to display the local preview screen*/
257-
TEXTUREVIEW = new TextureView(getContext());
258252
// call when join button hit
259253
String channelId = et_channel.getText().toString();
260254
// Check permission
@@ -280,7 +274,20 @@ public void onClick(View v) {
280274
screenSharePreview.setEnabled(false);
281275
fl_camera.removeAllViews();
282276
fl_screen.removeAllViews();
283-
engine.stopPreview();
277+
278+
if (camera.isChecked()) {
279+
engine.leaveChannelEx(rtcConnection2);
280+
camera.setChecked(false);
281+
}
282+
if(screenSharePreview.isChecked()){
283+
engine.stopPreview(Constants.VideoSourceType.VIDEO_SOURCE_SCREEN_PRIMARY);
284+
screenSharePreview.setChecked(false);
285+
}
286+
if(screenShare.isChecked()){
287+
engine.stopScreenCapture();
288+
screenShare.setChecked(false);
289+
}
290+
engine.stopPreview(Constants.VideoSourceType.VIDEO_SOURCE_CAMERA_PRIMARY);
284291
/**After joining a channel, the user must call the leaveChannel method to end the
285292
* call before joining another channel. This method returns 0 if the user leaves the
286293
* channel and releases all resources related to the call. This method call is
@@ -299,9 +306,8 @@ public void onClick(View v) {
299306
* 2:If you call the leaveChannel method during CDN live streaming, the SDK
300307
* triggers the removeInjectStreamUrl method.*/
301308
engine.leaveChannel();
302-
TEXTUREVIEW = null;
303309

304-
requireActivity().finish();
310+
//requireActivity().finish();
305311
}
306312
}
307313
}
@@ -356,11 +362,12 @@ private void joinChannel(String channelId) {
356362
engine.setParameters("{\"che.video.mobile_1080p\":true}");
357363
engine.setClientRole(Constants.CLIENT_ROLE_BROADCASTER);
358364
// set options
365+
options = new ChannelMediaOptions();
359366
options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER;
360367
options.autoSubscribeVideo = true;
361368
options.autoSubscribeAudio = true;
362369
options.publishCameraTrack = false;
363-
options.publishScreenTrack = true;
370+
options.publishScreenTrack = false;
364371
options.publishAudioTrack = false;
365372
options.enableAudioRecordingOrPlayout = false;
366373
options.publishEncodedVideoTrack = false;

0 commit comments

Comments
 (0)