Skip to content

Commit 7dee37a

Browse files
Merge pull request #32 from adfleshner/main
Removing AppCompatActivity in the CallQuery method
2 parents 4e7bc9d + c1dc5fb commit 7dee37a

28 files changed

+146
-177
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ FFmpeg Android runs on the following architectures:
7878

7979
```
8080
dependencies {
81-
implementation 'com.github.SimformSolutionsPvtLtd:SSffmpegVideoOperation:1.0.7'
81+
implementation 'com.github.SimformSolutionsPvtLtd:SSffmpegVideoOperation:1.0.8'
8282
}
8383
```
8484

@@ -88,7 +88,7 @@ This is all you have to do to load the FFmpeg library.
8888
In this sample code we will run the FFmpeg -version command in background call.
8989
```java
9090
val query:Array<String> = "-i, input,....,...., outout"
91-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
91+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
9292
override fun statisticsProcess(statistics: Statistics) {
9393
Log.i("FFMPEG LOG : ", statistics.videoFrameNumber)
9494
}
@@ -115,7 +115,7 @@ In this sample code we will run the FFmpeg -version command in background call.
115115
val startTimeString = "00:01:00" (HH:MM:SS)
116116
val endTimeString = "00:02:00" (HH:MM:SS)
117117
val query:Array<String> = FFmpegQueryExtension().cutVideo(inputPath, startTimeString, endTimeString, outputPath)
118-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
118+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
119119
override fun statisticsProcess(statistics: Statistics) {
120120
Log.i("FFMPEG LOG : ", statistics.videoFrameNumber)
121121
}

SSffmpegVideoOperation/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ afterEvaluate {
1212
from components.release
1313
groupId = 'com.simform.videooperations'
1414
artifactId = 'videooperations'
15-
version = '1.0.7'
15+
version = '1.0.8'
1616
}
1717
}
1818
}

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

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

3+
import android.os.Handler
4+
import android.os.Looper
35
import android.util.Log
4-
import androidx.appcompat.app.AppCompatActivity
56
import com.arthenica.mobileffmpeg.Config
67
import com.arthenica.mobileffmpeg.FFmpeg
78
import 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
}

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() {

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class CombineImageAndVideoActivity : BaseActivity(R.layout.activity_merge_image_
107107

108108
val query = ffmpegQueryExtension.combineImagesAndVideos(paths, width, height, edtSecond.text.toString(), outputPath)
109109

110-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
110+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
111111
override fun process(logMessage: LogMessage) {
112112
tvOutputPath.text = logMessage.text
113113
}
@@ -128,12 +128,10 @@ class CombineImageAndVideoActivity : BaseActivity(R.layout.activity_merge_image_
128128
}
129129

130130
private fun processStop() {
131-
runOnUiThread {
132-
btnVideoPath.isEnabled = true
133-
btnImagePath.isEnabled = true
134-
btnCombine.isEnabled = true
135-
mProgressView.visibility = View.GONE
136-
}
131+
btnVideoPath.isEnabled = true
132+
btnImagePath.isEnabled = true
133+
btnCombine.isEnabled = true
134+
mProgressView.visibility = View.GONE
137135
}
138136

139137
private fun processStart() {

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,9 @@ class CombineImagesActivity : BaseActivity(R.layout.activity_combine_images, R.s
6565
}
6666

6767
private fun processStop() {
68-
runOnUiThread {
69-
btnImagePath.isEnabled = true
70-
btnCombine.isEnabled = true
71-
mProgressView.visibility = View.GONE
72-
}
68+
btnImagePath.isEnabled = true
69+
btnCombine.isEnabled = true
70+
mProgressView.visibility = View.GONE
7371
}
7472

7573
private fun processStart() {
@@ -91,7 +89,7 @@ class CombineImagesActivity : BaseActivity(R.layout.activity_combine_images, R.s
9189

9290
val query = ffmpegQueryExtension.combineImagesAndVideos(pathsList, 640, 480, edtSecond.text.toString(), outputPath)
9391

94-
CallBackOfQuery().callQuery(this, query, object : FFmpegCallBack {
92+
CallBackOfQuery().callQuery(query, object : FFmpegCallBack {
9593
override fun process(logMessage: LogMessage) {
9694
tvOutputPath.text = logMessage.text
9795
}

0 commit comments

Comments
 (0)