Skip to content

Commit b4b7c44

Browse files
committed
fixed surface auto resize bug
1 parent 47b676a commit b4b7c44

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

app/src/main/res/layout/fragment_live.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
<SurfaceView
8484
android:id="@+id/svVideo"
85-
android:layout_width="match_parent"
85+
android:layout_width="wrap_content"
8686
android:layout_height="wrap_content" />
8787

8888
<ProgressBar

rtsp-client/src/main/java/ir/am3n/rtsp/client/codec/VideoDecoder.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ internal class VideoDecoder(
4040
srcRect.bottom = height
4141
dstRect.right = width
4242
dstRect.bottom = height
43-
surfaceView?.holder?.setFixedSize(width, height)
43+
if (width > height) {
44+
val rate = (surfaceView?.measuredWidth ?: 0).toFloat() / width.toFloat()
45+
val height = (height * rate).toInt()
46+
surfaceView?.holder?.setFixedSize(width, height)
47+
} else {
48+
val rate = (surfaceView?.measuredHeight ?: 0).toFloat() / height.toFloat()
49+
val width = (width * rate).toInt()
50+
surfaceView?.holder?.setFixedSize(width, height)
51+
}
4452
}
4553

4654
fun stopAsync() {

0 commit comments

Comments
 (0)