11package com.simform.videooperations
22
3+ import android.os.Handler
4+ import android.os.Looper
35import android.util.Log
4- import androidx.appcompat.app.AppCompatActivity
56import com.arthenica.mobileffmpeg.Config
67import com.arthenica.mobileffmpeg.FFmpeg
78import java.util.concurrent.CyclicBarrier
@@ -10,13 +11,13 @@ import java.util.concurrent.CyclicBarrier
1011 * Created by Ashvin Vavaliya on 22,January,2021
1112 * Simform Solutions Pvt Ltd.
1213 */
13- public class CallBackOfQuery {
14- fun callQuery (context : AppCompatActivity , query : Array <String >, fFmpegCallBack : FFmpegCallBack ) {
14+ class CallBackOfQuery {
15+ fun callQuery (query : Array <String >, fFmpegCallBack : FFmpegCallBack ) {
1516 val gate = CyclicBarrier (2 )
1617 object : Thread () {
1718 override fun run () {
1819 gate.await()
19- process(context, query, fFmpegCallBack)
20+ process(query, fFmpegCallBack)
2021 }
2122 }.start()
2223 gate.await()
@@ -34,29 +35,47 @@ public class CallBackOfQuery {
3435 FFmpeg .cancel()
3536 }
3637
37- private fun process (context : AppCompatActivity , query : Array <String >, ffmpegCallBack : FFmpegCallBack ) {
38+ private fun process (query : Array <String >, ffmpegCallBack : FFmpegCallBack ) {
39+ val processHandler = Handler (Looper .getMainLooper())
3840 Config .enableLogCallback { logMessage ->
3941 val logs = LogMessage (logMessage.executionId, logMessage.level, logMessage.text)
40- ffmpegCallBack.process(logs)
42+ processHandler.post {
43+ ffmpegCallBack.process(logs)
44+ }
4145 }
4246 Config .enableStatisticsCallback { statistics ->
4347 val statisticsLog =
44- Statistics (statistics.executionId, statistics.videoFrameNumber, statistics.videoFps, statistics.videoQuality, statistics.size, statistics.time, statistics.bitrate, statistics.speed)
45- ffmpegCallBack.statisticsProcess(statisticsLog)
48+ Statistics (
49+ statistics.executionId,
50+ statistics.videoFrameNumber,
51+ statistics.videoFps,
52+ statistics.videoQuality,
53+ statistics.size,
54+ statistics.time,
55+ statistics.bitrate,
56+ statistics.speed
57+ )
58+ processHandler.post {
59+ ffmpegCallBack.statisticsProcess(statisticsLog)
60+ }
4661 }
4762 when (FFmpeg .execute(query)) {
4863 Config .RETURN_CODE_SUCCESS -> {
49- context.runOnUiThread {
64+ processHandler.post {
5065 ffmpegCallBack.success()
5166 }
5267 }
5368 Config .RETURN_CODE_CANCEL -> {
54- ffmpegCallBack.cancel()
55- FFmpeg .cancel()
69+ processHandler.post {
70+ ffmpegCallBack.cancel()
71+ FFmpeg .cancel()
72+ }
5673 }
5774 else -> {
58- ffmpegCallBack.failed()
59- Config .printLastCommandOutput(Log .INFO )
75+ processHandler.post {
76+ ffmpegCallBack.failed()
77+ Config .printLastCommandOutput(Log .INFO )
78+ }
6079 }
6180 }
6281 }
0 commit comments