Skip to content

Commit aa90e32

Browse files
author
xia ning
authored
Merge pull request #180 from SongBaiw/master
Update ScreenSharingService.java
2 parents 8e37e23 + 697fa62 commit aa90e32

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,9 @@ public void onConnectionStateChanged(int state, int reason) {
335335
}
336336

337337
private void setUpVideoConfig(Intent intent) {
338-
int width = intent.getIntExtra(Constant.WIDTH, 0);
339-
int height = intent.getIntExtra(Constant.HEIGHT, 0);
338+
// 预置 1280*720 宽高
339+
float boundingSizewidth = 720;
340+
float boundingSizeheight = 1280;
340341
int frameRate = intent.getIntExtra(Constant.FRAME_RATE, 15);
341342
int bitRate = intent.getIntExtra(Constant.BITRATE, 0);
342343
int orientationMode = intent.getIntExtra(Constant.ORIENTATION_MODE, 0);
@@ -378,8 +379,26 @@ private void setUpVideoConfig(Intent intent) {
378379
om = VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
379380
break;
380381
}
381-
382+
// 计算实际宽高
383+
WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
384+
DisplayMetrics outMetrics = new DisplayMetrics();
385+
wm.getDefaultDisplay().getMetrics(outMetrics);
386+
float screenWidth = outMetrics.widthPixels;
387+
float screenHeight = outMetrics.heightPixels;
388+
Log.i(LOG_TAG, "setUpVideoConfig: " + screenWidth + "---" + screenHeight);
389+
float mW = boundingSizewidth / screenWidth;
390+
float mH = boundingSizeheight / screenHeight;
391+
Log.i(LOG_TAG, "setUpVideoConfig: " + mW + "---" + mH);
392+
if( mH < mW ) {
393+
boundingSizewidth = boundingSizeheight / screenHeight * screenWidth;
394+
Log.i(LOG_TAG, "boundingSizewidth: " + boundingSizewidth );
395+
}
396+
else if( mW < mH ) {
397+
boundingSizeheight = boundingSizewidth / screenWidth * screenHeight;
398+
Log.i(LOG_TAG, "boundingSizeheight:" + boundingSizeheight);
399+
}
400+
Log.i(LOG_TAG, "setUpVideoConfig: " + boundingSizewidth + "---" + boundingSizeheight);
382401
mRtcEngine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
383-
new VideoEncoderConfiguration.VideoDimensions(width, height), fr, bitRate, om));
402+
new VideoEncoderConfiguration.VideoDimensions((int) boundingSizewidth, (int) boundingSizeheight), fr, bitRate, om));
384403
}
385404
}

0 commit comments

Comments
 (0)