Skip to content

Commit 11a452e

Browse files
committed
Removing AppCompatActivity in the CallQuery method
Removed the AppComaptActivity Dependency for the callQuery method. Using Handler and post instead.
1 parent 4e7bc9d commit 11a452e

26 files changed

Lines changed: 133 additions & 172 deletions

SSffmpegVideoOperation/src/main/java/com/simform/videooperations/CallBackOfQuery.kt

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.simform.videooperations
22

3+
import android.os.Handler
4+
import android.os.Looper
35
import android.util.Log
46
import androidx.appcompat.app.AppCompatActivity
57
import com.arthenica.mobileffmpeg.Config
@@ -10,13 +12,13 @@ import java.util.concurrent.CyclicBarrier
1012
* Created by Ashvin Vavaliya on 22,January,2021
1113
* Simform Solutions Pvt Ltd.
1214
*/
13-
public class CallBackOfQuery {
14-
fun callQuery(context: AppCompatActivity, query: Array<String>, fFmpegCallBack: FFmpegCallBack) {
15+
class CallBackOfQuery {
16+
fun callQuery(query: Array<String>, fFmpegCallBack: FFmpegCallBack) {
1517
val gate = CyclicBarrier(2)
1618
object : Thread() {
1719
override fun run() {
1820
gate.await()
19-
process(context, query, fFmpegCallBack)
21+
process(query, fFmpegCallBack)
2022
}
2123
}.start()
2224
gate.await()
@@ -34,30 +36,39 @@ public class CallBackOfQuery {
3436
FFmpeg.cancel()
3537
}
3638

37-
private fun process(context: AppCompatActivity, query: Array<String>, ffmpegCallBack: FFmpegCallBack) {
39+
private fun process(query: Array<String>, ffmpegCallBack: FFmpegCallBack) {
40+
val processHandler = Handler(Looper.getMainLooper())
3841
Config.enableLogCallback { logMessage ->
3942
val logs = LogMessage(logMessage.executionId, logMessage.level, logMessage.text)
40-
ffmpegCallBack.process(logs)
43+
processHandler.post {
44+
ffmpegCallBack.process(logs)
45+
}
4146
}
4247
Config.enableStatisticsCallback { statistics ->
4348
val statisticsLog =
4449
Statistics(statistics.executionId, statistics.videoFrameNumber, statistics.videoFps, statistics.videoQuality, statistics.size, statistics.time, statistics.bitrate, statistics.speed)
45-
ffmpegCallBack.statisticsProcess(statisticsLog)
50+
processHandler.post {
51+
ffmpegCallBack.statisticsProcess(statisticsLog)
52+
}
4653
}
4754
when (FFmpeg.execute(query)) {
4855
Config.RETURN_CODE_SUCCESS -> {
49-
context.runOnUiThread {
56+
processHandler.post {
5057
ffmpegCallBack.success()
5158
}
5259
}
5360
Config.RETURN_CODE_CANCEL -> {
54-
ffmpegCallBack.cancel()
55-
FFmpeg.cancel()
61+
processHandler.post {
62+
ffmpegCallBack.cancel()
63+
FFmpeg.cancel()
64+
}
5665
}
5766
else -> {
58-
ffmpegCallBack.failed()
59-
Config.printLastCommandOutput(Log.INFO)
60-
}
67+
processHandler.post {
68+
ffmpegCallBack.failed()
69+
Config.printLastCommandOutput(Log.INFO)
70+
}
71+
}
6172
}
6273
}
6374
}

app/src/main/java/com/simform/videoimageeditor/otherFFMPEGProcessActivity/AudiosMergeActivity.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class AudiosMergeActivity : BaseActivity(R.layout.activity_audios_merge, R.strin
5757

5858
val query = ffmpegQueryExtension.mergeAudios(pathsList, DURATION_FIRST, outputPath)
5959

60-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
60+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
6161
override fun process(logMessage: LogMessage) {
6262
tvOutputPath.text = logMessage.text
6363
}
@@ -79,11 +79,9 @@ class AudiosMergeActivity : BaseActivity(R.layout.activity_audios_merge, R.strin
7979
}
8080

8181
private fun processStop() {
82-
runOnUiThread {
83-
btnAudioPath.isEnabled = true
84-
btnMerge.isEnabled = true
85-
mProgressView.visibility = View.GONE
86-
}
82+
btnAudioPath.isEnabled = true
83+
btnMerge.isEnabled = true
84+
mProgressView.visibility = View.GONE
8785
}
8886

8987
private fun processStart() {

app/src/main/java/com/simform/videoimageeditor/otherFFMPEGProcessActivity/ChangeAudioVolumeActivity.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ChangeAudioVolumeActivity : BaseActivity(R.layout.activity_change_audio_va
4545
private fun mergeAudioProcess() {
4646
val outputPath = Common.getFilePath(this, Common.MP3)
4747
val query = ffmpegQueryExtension.audioVolumeUpdate(tvInputPathAudio.text.toString(), volume = 0.1f, output = outputPath)
48-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
48+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
4949
override fun process(logMessage: LogMessage) {
5050
tvOutputPath.text = logMessage.text
5151
}
@@ -66,11 +66,9 @@ class ChangeAudioVolumeActivity : BaseActivity(R.layout.activity_change_audio_va
6666
}
6767

6868
private fun processStop() {
69-
runOnUiThread {
70-
btnAudioPath.isEnabled = true
71-
btnChange.isEnabled = true
72-
mProgressView.visibility = View.GONE
73-
}
69+
btnAudioPath.isEnabled = true
70+
btnChange.isEnabled = true
71+
mProgressView.visibility = View.GONE
7472
}
7573

7674
private fun processStart() {

app/src/main/java/com/simform/videoimageeditor/otherFFMPEGProcessActivity/CompressAudioActivity.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CompressAudioActivity : BaseActivity(R.layout.activity_compress_audio, R.s
4646
private fun compressAudioProcess() {
4747
val outputPath = Common.getFilePath(this, Common.MP3)
4848
val query = ffmpegQueryExtension.compressAudio(inputAudioPath = tvInputPathAudio.text.toString(), bitrate = BITRATE_128, output = outputPath)
49-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
49+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
5050
override fun process(logMessage: LogMessage) {
5151
tvOutputPath.text = logMessage.text
5252
}
@@ -67,11 +67,9 @@ class CompressAudioActivity : BaseActivity(R.layout.activity_compress_audio, R.s
6767
}
6868

6969
private fun processStop() {
70-
runOnUiThread {
71-
btnAudioPath.isEnabled = true
72-
btnChange.isEnabled = true
73-
mProgressView.visibility = View.GONE
74-
}
70+
btnAudioPath.isEnabled = true
71+
btnChange.isEnabled = true
72+
mProgressView.visibility = View.GONE
7573
}
7674

7775
private fun processStart() {

app/src/main/java/com/simform/videoimageeditor/otherFFMPEGProcessActivity/CropAudioActivity.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class CropAudioActivity : BaseActivity(R.layout.activity_crop_audio, R.string.cr
147147
private fun cutProcess() {
148148
val outputPath = Common.getFilePath(this, Common.MP3)
149149
val query = ffmpegQueryExtension.cutAudio(tvInputPath.text.toString(), startTimeString, endTimeString, outputPath)
150-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
150+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
151151
override fun process(logMessage: LogMessage) {
152152
tvOutputPath.text = logMessage.text
153153
}
@@ -168,13 +168,11 @@ class CropAudioActivity : BaseActivity(R.layout.activity_crop_audio, R.string.cr
168168
}
169169

170170
private fun processStop() {
171-
runOnUiThread {
172-
btnAudioPath.isEnabled = true
173-
btnSelectStartTime.isEnabled = true
174-
btnSelectEndTime.isEnabled = true
175-
btnConvert.isEnabled = true
176-
mProgressView.visibility = View.GONE
177-
}
171+
btnAudioPath.isEnabled = true
172+
btnSelectStartTime.isEnabled = true
173+
btnSelectEndTime.isEnabled = true
174+
btnConvert.isEnabled = true
175+
mProgressView.visibility = View.GONE
178176
}
179177

180178
private fun processStart() {

app/src/main/java/com/simform/videoimageeditor/otherFFMPEGProcessActivity/FastAndSlowAudioActivity.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class FastAndSlowAudioActivity : BaseActivity(R.layout.activity_fast_and_slow_au
5050
atempo = 0.5
5151
}
5252
val query = ffmpegQueryExtension.audioMotion(tvInputPathAudio.text.toString(), outputPath, atempo)
53-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
53+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
5454
override fun process(logMessage: LogMessage) {
5555
tvOutputPath.text = logMessage.text
5656
}
@@ -84,11 +84,9 @@ class FastAndSlowAudioActivity : BaseActivity(R.layout.activity_fast_and_slow_au
8484
}
8585

8686
private fun processStop() {
87-
runOnUiThread {
88-
btnAudioPath.isEnabled = true
89-
btnMotion.isEnabled = true
90-
mProgressView.visibility = View.GONE
91-
}
87+
btnAudioPath.isEnabled = true
88+
btnMotion.isEnabled = true
89+
mProgressView.visibility = View.GONE
9290
}
9391

9492
private fun processStart() {

app/src/main/java/com/simform/videoimageeditor/otherFFMPEGProcessActivity/MergeGIFActivity.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class MergeGIFActivity : BaseActivity(R.layout.activity_merge_gif, R.string.merg
109109
}
110110
val query = ffmpegQueryExtension.mergeGIF(pathsList, xPos, yPos, widthScale, heightScale, outputPath)
111111

112-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
112+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
113113
override fun process(logMessage: LogMessage) {
114114
tvOutputPath.text = logMessage.text
115115
}
@@ -131,11 +131,9 @@ class MergeGIFActivity : BaseActivity(R.layout.activity_merge_gif, R.string.merg
131131
}
132132

133133
private fun processStop() {
134-
runOnUiThread {
135-
btnGifPath.isEnabled = true
136-
btnMerge.isEnabled = true
137-
mProgressView.visibility = View.GONE
138-
}
134+
btnGifPath.isEnabled = true
135+
btnMerge.isEnabled = true
136+
mProgressView.visibility = View.GONE
139137
}
140138

141139
private fun processStart() {

app/src/main/java/com/simform/videoimageeditor/videoProcessActivity/AddTextOnVideoActivity.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class AddTextOnVideoActivity : BaseActivity(R.layout.activity_add_text_on_video,
7575
}
7676
val fontPath = getFileFromAssets(this, "little_lord.ttf").absolutePath
7777
val query = ffmpegQueryExtension.addTextOnVideo(tvInputPathVideo.text.toString(), edtText.text.toString(), xPos, yPos, fontPath = fontPath, isTextBackgroundDisplay = true, fontSize = 28, fontcolor = "red", output = outputPath)
78-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
78+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
7979
override fun process(logMessage: LogMessage) {
8080
tvOutputPath.text = logMessage.text
8181
}
@@ -96,11 +96,9 @@ class AddTextOnVideoActivity : BaseActivity(R.layout.activity_add_text_on_video,
9696
}
9797

9898
private fun processStop() {
99-
runOnUiThread {
100-
btnVideoPath.isEnabled = true
101-
btnAdd.isEnabled = true
102-
mProgressView.visibility = View.GONE
103-
}
99+
btnVideoPath.isEnabled = true
100+
btnAdd.isEnabled = true
101+
mProgressView.visibility = View.GONE
104102
}
105103

106104
private fun processStart() {

app/src/main/java/com/simform/videoimageeditor/videoProcessActivity/AddWaterMarkOnVideoActivity.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class AddWaterMarkOnVideoActivity : BaseActivity(R.layout.activity_add_water_mar
110110
(edtYPos.text.toString().toFloat().times(it)).div(100)
111111
}
112112
val query = ffmpegQueryExtension.addVideoWaterMark(tvInputPathVideo.text.toString(), tvInputPathImage.text.toString(), xPos, yPos, outputPath)
113-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
113+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
114114
override fun process(logMessage: LogMessage) {
115115
tvOutputPath.text = logMessage.text
116116
}
@@ -131,12 +131,10 @@ class AddWaterMarkOnVideoActivity : BaseActivity(R.layout.activity_add_water_mar
131131
}
132132

133133
private fun processStop() {
134-
runOnUiThread {
135-
btnVideoPath.isEnabled = true
136-
btnImagePath.isEnabled = true
137-
btnAdd.isEnabled = true
138-
mProgressView.visibility = View.GONE
139-
}
134+
btnVideoPath.isEnabled = true
135+
btnImagePath.isEnabled = true
136+
btnAdd.isEnabled = true
137+
mProgressView.visibility = View.GONE
140138
}
141139

142140
private fun processStart() {

app/src/main/java/com/simform/videoimageeditor/videoProcessActivity/AspectRatioActivity.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AspectRatioActivity : BaseActivity(R.layout.activity_aspect_ratio, R.strin
4848
val outputPath = Common.getFilePath(this, Common.VIDEO)
4949
val query = ffmpegQueryExtension.applyRatio(tvInputPathVideo.text.toString(), RATIO_1, outputPath)
5050

51-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
51+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
5252
override fun process(logMessage: LogMessage) {
5353
tvOutputPath.text = logMessage.text
5454
}
@@ -84,11 +84,9 @@ class AspectRatioActivity : BaseActivity(R.layout.activity_aspect_ratio, R.strin
8484
}
8585

8686
private fun processStop() {
87-
runOnUiThread {
88-
btnVideoPath.isEnabled = true
89-
btnAspectRatio.isEnabled = true
90-
mProgressView.visibility = View.GONE
91-
}
87+
btnVideoPath.isEnabled = true
88+
btnAspectRatio.isEnabled = true
89+
mProgressView.visibility = View.GONE
9290
}
9391

9492
private fun processStart() {

0 commit comments

Comments
 (0)