Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: permission is denied using Android 10 #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ android {
buildToolsVersion rootProject.ext.buildToolsVersion as String
defaultConfig {
applicationId "com.cleveroad.bootstrap.kotlin"
minSdkVersion 21
minSdkVersion 19
targetSdkVersion rootProject.ext.compileSdkVersion as Integer
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}

buildTypes {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:requestLegacyExternalStorage="true"
android:extractNativeLibs="true"
tools:ignore="GoogleAppIndexingWarning">

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class FFMpegActivity : AppCompatActivity(), View.OnClickListener {
setClickListeners(bPickFile, bPickOverlayFile, bCreateThumbnails, bCompressVideo)
}

override fun onDestroy() {
super.onDestroy()
CompressVideoBuilder.with(this).cancel()
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ task clean(type: Delete) {
}

ext {
compileSdkVersion = 28
minSdkVersion = 16
buildToolsVersion = '28.0.3'
targetSdkVersion = 28
compileSdkVersion = 29
minSdkVersion = 18
buildToolsVersion = '29.0.3'
targetSdkVersion = 29
}

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class BaseArrayAdapter<T>(context: Context) : ArrayAdapter<T>(context,

override fun getNonFilteredCount() = super.getCount()

override fun getNonFilteredItem(position: Int) = super.getItem(position)
override fun getNonFilteredItem(position: Int) : T? = super.getItem(position)

/**
* Adds the specified items at the end of the array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ abstract class BaseFilter<T>(highlightColor: Int) : Filter() {

internal interface FilterableAdapter<T> {
fun getNonFilteredCount(): Int
fun getNonFilteredItem(position: Int): T
fun getNonFilteredItem(position: Int): T?
fun notifyDataSetChanged()
fun withFilter(filter: BaseFilter<T>?)
fun highlightFilteredSubstring(text: String): Spannable
Expand Down
2 changes: 1 addition & 1 deletion kotlin-ffmpeg-thumbnails/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ dependencies {
implementation rxjava2Dependencies.rxkotlin
implementation rxjava2Dependencies.rxandroid

implementation 'nl.bravobit:android-ffmpeg:1.1.5'
implementation 'com.github.scmfaria:FFmpeg-Android:1.2.1'
implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'
}
2 changes: 1 addition & 1 deletion kotlin-ffmpeg-video-compress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ dependencies {
implementation rxjava2Dependencies.rxkotlin
implementation rxjava2Dependencies.rxandroid

implementation 'nl.bravobit:android-ffmpeg:1.1.5'
implementation 'com.github.scmfaria:FFmpeg-Android:1.2.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.cleveroad.bootstrap.kotlin_ffmpeg_video_compress.Constants.VIDEO_CODE
import com.cleveroad.bootstrap.kotlin_ffmpeg_video_compress.Constants.VIDEO_MP4
import com.cleveroad.bootstrap.kotlin_ffmpeg_video_compress.Constants.VIDEO_RATE
import com.cleveroad.bootstrap.kotlin_ffmpeg_video_compress.FFmpegHelper.execFFmpegBinary
import com.cleveroad.bootstrap.kotlin_ffmpeg_video_compress.FFmpegHelper.killProcess
import com.cleveroad.bootstrap.kotlin_ffmpeg_video_compress.TimeUtils.timeToMs
import com.cleveroad.bootstrap.kotlin_ffmpeg_video_compress.types.PresetType
import com.cleveroad.bootstrap.kotlin_ffmpeg_video_compress.types.StrictType
Expand Down Expand Up @@ -194,6 +195,13 @@ class CompressVideoBuilder private constructor(private val context: Context) {
})
}

/**
* Cancel ffmpeg command
*/
fun cancel() {
killProcess()
}


private fun calculateComplexCommand(bitrate: Long, duration: Long, outPath: String) = mutableListOf<String>().apply {
if (isOverride) add(OVERRIDE_EXISTING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,64 @@ import io.reactivex.BackpressureStrategy
import io.reactivex.Flowable
import nl.bravobit.ffmpeg.ExecuteBinaryResponseHandler
import nl.bravobit.ffmpeg.FFmpeg

import nl.bravobit.ffmpeg.FFtask

object FFmpegHelper {

private var isSupported = false

private fun checkIsSupported(ffmpeg: FFmpeg): Flowable<FFmpeg> =
Flowable.create<FFmpeg>({ emit ->
if (isSupported) {
Flowable.create<FFmpeg>({ emit ->
if (isSupported) {
emit.onNext(ffmpeg)
} else {
if (ffmpeg.isSupported) {
isSupported = true
emit.onNext(ffmpeg)
} else {
if (ffmpeg.isSupported) {
isSupported = true
emit.onNext(ffmpeg)
} else {
isSupported = false
emit.onError(UnsupportedOperationException())

}
isSupported = false
emit.onError(UnsupportedOperationException())

}
}, BackpressureStrategy.BUFFER)
}
}, BackpressureStrategy.BUFFER)

private var ffmpeg: FFmpeg? = null
private var ffTask: FFtask? = null

fun execFFmpegBinary(command: Array<String>, context: Context, videoLengthInMillis: Long? = null) =
Flowable.fromCallable { FFmpeg.getInstance(context) }
.flatMap { checkIsSupported(it) }
.flatMap { ffmpeg ->
Flowable.create<Long>({ emit ->
ffmpeg.execute(command, object : ExecuteBinaryResponseHandler() {
override fun onFailure(s: String?) = emit.onError(Throwable(s))

override fun onSuccess(s: String?) {
emit.onNext(PERCENT_SUCCESSFULLY)
emit.onComplete()
}
Flowable.fromCallable { FFmpeg.getInstance(context) }
.flatMap { checkIsSupported(it) }
.flatMap {
Flowable.create<Long>({ emit ->
ffmpeg = it
ffTask = it.execute(command, object : ExecuteBinaryResponseHandler() {
override fun onFailure(s: String?) = emit.onError(Throwable(s))

override fun onSuccess(s: String?) {
emit.onNext(PERCENT_SUCCESSFULLY)
emit.onComplete()
}

override fun onProgress(s: String?) {
s?.takeIf { videoLengthInMillis != null }?.let {
getProgress(s, videoLengthInMillis
?: 0).takeIf { it in 1..99 }?.let {
emit.onNext(it)
}
}
override fun onProgress(s: String?) {
s?.takeIf { videoLengthInMillis != null }?.let {
getProgress(s, videoLengthInMillis
?: 0).takeIf { it in 1..99 }?.let {
emit.onNext(it)
}
}
}

override fun onStart() = Unit
override fun onFinish() = Unit
})

override fun onStart() = Unit
override fun onFinish() = Unit
})
}, BackpressureStrategy.LATEST)
}

}, BackpressureStrategy.LATEST)
}
fun killProcess() {
ffmpeg?.apply {
killRunningProcesses(ffTask)
}
}
}
2 changes: 1 addition & 1 deletion kotlin-phone-input/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
buildToolsVersion rootProject.ext.buildToolsVersion as String

defaultConfig {
minSdkVersion 21
minSdkVersion 18
targetSdkVersion rootProject.ext.compileSdkVersion as Integer
versionCode libraryVersionCode
versionName libraryVersion
Expand Down
4 changes: 2 additions & 2 deletions main_jcenter.settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ext {
libraryVersionCode = 30
libraryVersion = '2.0.0'
libraryVersionCode = 33
libraryVersion = '2.1.2'
}