1
1
package com.lalilu.fpcalc
2
2
3
+ import android.annotation.SuppressLint
3
4
import android.os.Bundle
5
+ import android.widget.Button
4
6
import android.widget.TextView
5
7
import androidx.appcompat.app.AppCompatActivity
6
8
import com.blankj.utilcode.util.FileIOUtils
@@ -15,18 +17,32 @@ class MainActivity : AppCompatActivity() {
15
17
super .onCreate(savedInstanceState)
16
18
setContentView(R .layout.activity_main)
17
19
20
+ findViewById<Button >(R .id.retry).setOnClickListener {
21
+ calc()
22
+ }
23
+
24
+ calc()
25
+ }
26
+
27
+ @SuppressLint(" SetTextI18n" )
28
+ fun calc () {
18
29
GlobalScope .launch(Dispatchers .IO ) {
19
30
val tempFile = File (cacheDir, " tempAudio" )
20
31
val inputStream = resources.openRawResource(R .raw.test)
21
32
FileIOUtils .writeFileFromIS(tempFile, inputStream)
22
33
// 使用openRawResourceFd获取到的fd用于Fpcalc进行读取会导致MediaExtractor创建失败
23
34
// 故先通过读取流后,写入到cache文件夹中,再将该文件的path用于读取测试
24
35
25
- val params = FpcalcParams (targetFilePath = tempFile.path)
26
- val result = Fpcalc .calc(params)
36
+ val params: FpcalcParams = FpcalcParams (targetFilePath = tempFile.path)
37
+ val result: FpcalcResult = Fpcalc .calc(params)
38
+
39
+ val startTime = System .currentTimeMillis()
27
40
28
41
withContext(Dispatchers .Main ) {
29
- this @MainActivity.findViewById<TextView >(R .id.result).text = " $result "
42
+ this @MainActivity.findViewById<TextView >(R .id.result).text = """
43
+ startTime: $startTime
44
+ result:$result
45
+ """ .trimIndent()
30
46
}
31
47
}
32
48
}
0 commit comments