Skip to content

Commit

Permalink
修复悬浮球在旋转后位置移动导致溢出的问题,修复可能未正确旋转的问题,每2~3秒主动检测一次是否旋转
Browse files Browse the repository at this point in the history
  • Loading branch information
mingzhixian committed Apr 20, 2023
1 parent 1e3475d commit a58c0b2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
4 changes: 2 additions & 2 deletions scrcpy_android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "top.saymzx.scrcpy_android"
minSdk 23
targetSdk 33
versionCode 60
versionName "6.0"
versionCode 61
versionName "6.1"
resConfigs "zh"
ndk {
abiFilter "arm64-v8a"
Expand Down
4 changes: 2 additions & 2 deletions scrcpy_android/app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 60,
"versionName": "6.0",
"versionCode": 61,
"versionName": "6.1",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,36 +363,20 @@ class MainActivity : AppCompatActivity() {
var outIndex: Int
val bufferInfo = BufferInfo()
if (mode == "video") {
var decodeNum = 0
while (true) {
// 找到已完成的输出缓冲区
outIndex = configs.videoDecodec.dequeueOutputBuffer(bufferInfo, 0)
if (outIndex >= 0) {
// 每120帧(两秒)检查一次是否旋转,防止未收到旋转信息
decodeNum++
if (decodeNum > 119) {
decodeNum = 0
ifRotation(configs.videoDecodec.getOutputFormat(outIndex))
}
configs.videoDecodec.releaseOutputBuffer(outIndex, true)
} else if (outIndex == INFO_OUTPUT_FORMAT_CHANGED) {
val fomat = configs.videoDecodec.outputFormat
configs.remoteWidth = fomat.getInteger("width")
configs.remoteHeight = fomat.getInteger("height")
// 检测是否旋转
if ((configs.remoteWidth > configs.remoteHeight && configs.localWidth < configs.localHeight) || (configs.remoteWidth < configs.remoteHeight && configs.localWidth > configs.localHeight)) {
// surface
var tmp = configs.localWidth
configs.localWidth = configs.localHeight
configs.localHeight = tmp
configs.surfaceLayoutParams.apply {
width = configs.localWidth
height = configs.localHeight
}
// 导航球
tmp = configs.navLayoutParams.x
configs.navLayoutParams.x = configs.localWidth - configs.navLayoutParams.y
configs.navLayoutParams.y = tmp
runOnUiThread {
windowManager.updateViewLayout(configs.surfaceView, configs.surfaceLayoutParams)
windowManager.updateViewLayout(configs.navView, configs.navLayoutParams)
}
requestedOrientation =
if (configs.remoteWidth > configs.remoteHeight) ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE else ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
}
ifRotation(configs.videoDecodec.outputFormat)
} else {
Thread.sleep(8)
continue
Expand Down Expand Up @@ -449,6 +433,39 @@ class MainActivity : AppCompatActivity() {
}
}

// 判断是否旋转
private fun ifRotation(format: MediaFormat) {
configs.remoteWidth = format.getInteger("width")
configs.remoteHeight = format.getInteger("height")
// 检测是否旋转
if ((configs.remoteWidth > configs.remoteHeight && configs.localWidth < configs.localHeight) || (configs.remoteWidth < configs.remoteHeight && configs.localWidth > configs.localHeight)) {
// surface
var tmp = configs.localWidth
configs.localWidth = configs.localHeight
configs.localHeight = tmp
configs.surfaceLayoutParams.apply {
width = configs.localWidth
height = configs.localHeight
}
// 导航球,旋转不改变位置
if (configs.remoteWidth > configs.remoteHeight) {
tmp = configs.navLayoutParams.y
configs.navLayoutParams.y = configs.localHeight - configs.navLayoutParams.x - 170
configs.navLayoutParams.x = tmp
} else {
tmp = configs.navLayoutParams.x
configs.navLayoutParams.x = configs.localWidth - configs.navLayoutParams.y - 170
configs.navLayoutParams.y = tmp
}
runOnUiThread {
windowManager.updateViewLayout(configs.surfaceView, configs.surfaceLayoutParams)
windowManager.updateViewLayout(configs.navView, configs.navLayoutParams)
}
requestedOrientation =
if (configs.remoteWidth > configs.remoteHeight) ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE else ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
}
}

// 悬浮控制
@SuppressLint("ClickableViewAccessibility", "InflateParams")
private fun setFloatNav() {
Expand Down

0 comments on commit a58c0b2

Please sign in to comment.