From 80281e97403fa550e726981ca7c5071f0354a895 Mon Sep 17 00:00:00 2001
From: Dana <Dana_Lee1016@126.com>
Date: 星期二, 27 一月 2026 11:21:39 +0800
Subject: [PATCH] 1.设置数据源:setAudioSource() 和 setVideoSource()(必须在 setOutputFormat 之前)   设置输出格式:setOutputFormat()(必须在 setOutputFile 和编码器之前)   设置输出文件:setOutputFile()(必须在编码器之前)   设置编码器:setAudioEncoder() 和 setVideoEncoder()(必须在 setOutputFormat 之后)   设置编码参数:setAudioEncodingBitRate(), setAudioSamplingRate(), setVideoEncodingBitRate() 等(必须在编码器之后)   准备:prepare()

---
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab                     |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len                       |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i                         |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at                |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab.values.at           |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab                        |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at              |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at                 |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab                           |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at        |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab                             |    2 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab                          |    0 
 app/build/intermediates/desugar_graph/debug/dexBuilderDebug/out/currentProject/dirs_bucket_9/graph.bin    |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab                           |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len             |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab           |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at                 |    0 
 app/src/main/java/com/safeluck/floatwindow/MainActivity.kt                                                |   50 ++++++++++++++-----------
 app/src/main/java/com/safeluck/floatwindow/manager/AndroidCameraRecordManager.java                        |   18 ++++++++
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab                  |    0 
 app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream                 |    0 
 22 files changed, 46 insertions(+), 24 deletions(-)

diff --git a/app/build/intermediates/desugar_graph/debug/dexBuilderDebug/out/currentProject/dirs_bucket_9/graph.bin b/app/build/intermediates/desugar_graph/debug/dexBuilderDebug/out/currentProject/dirs_bucket_9/graph.bin
index 2f3be31..07e41e9 100644
--- a/app/build/intermediates/desugar_graph/debug/dexBuilderDebug/out/currentProject/dirs_bucket_9/graph.bin
+++ b/app/build/intermediates/desugar_graph/debug/dexBuilderDebug/out/currentProject/dirs_bucket_9/graph.bin
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab
index bdf584a..a314e47 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at
index 53b2d29..fc0e221 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab
index bdf584a..c0e915b 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at
index e9060a7..dac5c8e 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab
index 1a1fdbf..7315934 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab.values.at b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab.values.at
index 1d49f50..960edd7 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab.values.at
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/package-parts.tab.values.at
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab
index bdf584a..255bbf4 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at
index 1429ce6..5f42412 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab
index bdf584a..0feea10 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at
index 51508d6..043908f 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab
index 26d3b09..4a12dea 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab
@@ -1,2 +1,2 @@
-4
+5
 0
\ No newline at end of file
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab
index 2b3434a..f9463a0 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at
index 3e23c2a..f6a4f17 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab
index 4b0ca2c..f2aff74 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream
index 6e7a926..1dd772c 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len
index eb52963..62f3e6f 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len
index 93a595b..ec8f944 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at
index 42c4888..d073f36 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at
Binary files differ
diff --git a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i
index 6936967..e6ff6ac 100644
--- a/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i
+++ b/app/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i
Binary files differ
diff --git a/app/src/main/java/com/safeluck/floatwindow/MainActivity.kt b/app/src/main/java/com/safeluck/floatwindow/MainActivity.kt
index 4d19696..b4c07f6 100644
--- a/app/src/main/java/com/safeluck/floatwindow/MainActivity.kt
+++ b/app/src/main/java/com/safeluck/floatwindow/MainActivity.kt
@@ -22,6 +22,9 @@
 
 class MainActivity : ComponentActivity() {
     private var mediaAidlInterface: IMediaAidlInterface? = null
+    private var serviceConnection: ServiceConnection? = null
+    private var isServiceBound = false
+    private val isServiceBoundState = mutableStateOf(false)
     
     private val callback = object : IMyCallback.Stub() {
         @Throws(RemoteException::class)
@@ -36,18 +39,18 @@
         super.onCreate(savedInstanceState)
         enableEdgeToEdge()
         
-        var isServiceBoundState by mutableStateOf(false)
-        
-        val serviceConnection = object : ServiceConnection {
+        serviceConnection = object : ServiceConnection {
             override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
                 mediaAidlInterface = IMediaAidlInterface.Stub.asInterface(service)
-                isServiceBoundState = true
+                isServiceBound = true
+                isServiceBoundState.value = true
                 Timber.d("FloatingService connected")
             }
             
             override fun onServiceDisconnected(name: ComponentName?) {
                 mediaAidlInterface = null
-                isServiceBoundState = false
+                isServiceBound = false
+                isServiceBoundState.value = false
                 Timber.d("FloatingService disconnected")
             }
         }
@@ -59,26 +62,16 @@
                     color = MaterialTheme.colorScheme.background
                 ) {
                     MainScreen(
-                        isServiceBound = isServiceBoundState,
+                        isServiceBound = isServiceBoundState.value,
                         onBindService = { 
-                            if (!isServiceBoundState) {
+                            if (!isServiceBoundState.value && serviceConnection != null) {
                                 val intent = Intent(this@MainActivity, FloatingService::class.java)
-                                bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE)
+                                bindService(intent, serviceConnection!!, Context.BIND_AUTO_CREATE)
                                 Timber.d("Binding FloatingService")
                             }
                         },
                         onUnbindService = { 
-                            if (isServiceBoundState) {
-                                try {
-                                    mediaAidlInterface?.unregisterCallback(callback)
-                                } catch (e: RemoteException) {
-                                    Timber.e(e, "Error unregistering callback")
-                                }
-                                unbindService(serviceConnection)
-                                isServiceBoundState = false
-                                mediaAidlInterface = null
-                                Timber.d("Unbinding FloatingService")
-                            }
+                            unbindServiceInternal()
                         },
                         onStartAndroidRecord = { startAndroidRecord() },
                         onStopAndroidRecord = { stopAndroidRecord() },
@@ -210,16 +203,29 @@
         }
     }
     
-    override fun onDestroy() {
-        super.onDestroy()
-        if (mediaAidlInterface != null) {
+    private fun unbindServiceInternal() {
+        if (isServiceBound && serviceConnection != null) {
             try {
                 mediaAidlInterface?.unregisterCallback(callback)
             } catch (e: RemoteException) {
                 Timber.e(e, "Error unregistering callback")
             }
+            try {
+                unbindService(serviceConnection!!)
+                Timber.d("Unbinding FloatingService")
+            } catch (e: Exception) {
+                Timber.e(e, "Error unbinding service")
+            }
+            isServiceBound = false
+            isServiceBoundState.value = false
+            mediaAidlInterface = null
         }
     }
+    
+    override fun onDestroy() {
+        super.onDestroy()
+        unbindServiceInternal()
+    }
 }
 
 @Composable
diff --git a/app/src/main/java/com/safeluck/floatwindow/manager/AndroidCameraRecordManager.java b/app/src/main/java/com/safeluck/floatwindow/manager/AndroidCameraRecordManager.java
index 98f6fc6..a625b59 100644
--- a/app/src/main/java/com/safeluck/floatwindow/manager/AndroidCameraRecordManager.java
+++ b/app/src/main/java/com/safeluck/floatwindow/manager/AndroidCameraRecordManager.java
@@ -186,15 +186,31 @@
             }
             
             // 璁剧疆MediaRecorder
+            // 娉ㄦ剰锛歁ediaRecorder鐨勮缃『搴忛潪甯搁噸瑕侊紝蹇呴』涓ユ牸鎸夌収浠ヤ笅椤哄簭锛�
             mediaRecorder = new MediaRecorder();
+            
+            // 1. 璁剧疆鏁版嵁婧愶紙蹇呴』鍦╯etOutputFormat涔嬪墠锛�
+            mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
             mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
+            
+            // 2. 璁剧疆杈撳嚭鏍煎紡锛堝繀椤诲湪setOutputFile鍜岀紪鐮佸櫒涔嬪墠锛�
             mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
+            
+            // 3. 璁剧疆杈撳嚭鏂囦欢锛堝繀椤诲湪缂栫爜鍣ㄤ箣鍓嶏級
             mediaRecorder.setOutputFile(currentVideoFile.getAbsolutePath());
+            
+            // 4. 璁剧疆缂栫爜鍣紙蹇呴』鍦╯etOutputFormat涔嬪悗锛�
+            mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
+            mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
+            
+            // 5. 璁剧疆缂栫爜鍙傛暟锛堝繀椤诲湪缂栫爜鍣ㄤ箣鍚庯級
+            mediaRecorder.setAudioEncodingBitRate(64000); // 64kbps
+            mediaRecorder.setAudioSamplingRate(44100); // 44.1kHz
             mediaRecorder.setVideoEncodingBitRate(width * height * 3);
             mediaRecorder.setVideoFrameRate(20);
             mediaRecorder.setVideoSize(width, height);
-            mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
             
+            // 6. 鍑嗗MediaRecorder
             mediaRecorder.prepare();
             
             // 鍒涘缓Surface

--
Gitblit v1.8.0