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

fix deleteAllCache error in Android Plugin #123

Open
wants to merge 1 commit 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions android/src/main/kotlin/com/example/video_compress/Utility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.graphics.Bitmap
import android.media.MediaMetadataRetriever
import android.net.Uri
import android.os.Build
import io.flutter.plugin.common.MethodChannel
import org.json.JSONObject
import java.io.File
Expand Down Expand Up @@ -43,20 +42,12 @@ class Utility(private val channelName: String) {
val widthStr = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)
val heightStr = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)
val duration = java.lang.Long.parseLong(durationStr)
var width = java.lang.Long.parseLong(widthStr)
var height = java.lang.Long.parseLong(heightStr)
val width = java.lang.Long.parseLong(widthStr)
val height = java.lang.Long.parseLong(heightStr)
val filesize = file.length()
val orientation = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
val orientation =
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION)
} else {
null
}
val ori = orientation?.toIntOrNull()
if (ori != null && isLandscapeImage(ori)) {
val tmp = width
width = height
height = tmp
}

retriever.release()

Expand Down Expand Up @@ -127,8 +118,8 @@ class Utility(private val channelName: String) {
return fileName
}

fun deleteAllCache(context: Context, result: MethodChannel.Result) {
fun deleteAllCache(context: Context): Boolean {
val dir = context.getExternalFilesDir("video_compress")
result.success(dir?.deleteRecursively())
return dir?.deleteRecursively() ?: false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import android.net.Uri
import android.util.Log
import com.otaliastudios.transcoder.Transcoder
import com.otaliastudios.transcoder.TranscoderListener
import com.otaliastudios.transcoder.internal.Logger
import com.otaliastudios.transcoder.source.TrimDataSource
import com.otaliastudios.transcoder.source.UriDataSource
import com.otaliastudios.transcoder.strategy.DefaultAudioStrategy
import com.otaliastudios.transcoder.strategy.DefaultVideoStrategy
import com.otaliastudios.transcoder.strategy.RemoveTrackStrategy
import com.otaliastudios.transcoder.strategy.TrackStrategy
import com.otaliastudios.transcoder.strategy.size.*
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.BinaryMessenger
import com.otaliastudios.transcoder.internal.Logger
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
Expand Down Expand Up @@ -65,7 +64,7 @@ class VideoCompressPlugin : MethodCallHandler, FlutterPlugin {
result.success(Utility(channelName).getMediaInfoJson(context, path!!).toString())
}
"deleteAllCache" -> {
result.success(Utility(channelName).deleteAllCache(context, result));
result.success(Utility(channelName).deleteAllCache(context))
}
"setLogLevel" -> {
val logLevel = call.argument<Int>("logLevel")!!
Expand All @@ -86,7 +85,7 @@ class VideoCompressPlugin : MethodCallHandler, FlutterPlugin {
val frameRate = if (call.argument<Int>("frameRate")==null) 30 else call.argument<Int>("frameRate")

val tempDir: String = context.getExternalFilesDir("video_compress")!!.absolutePath
val out = SimpleDateFormat("yyyy-MM-dd hh-mm-ss").format(Date())
val out = SimpleDateFormat("yyyy-MM-dd_hh-mm-ss", Locale.US).format(Date())
val destPath: String = tempDir + File.separator + "VID_" + out + ".mp4"

var videoTrackStrategy: TrackStrategy = DefaultVideoStrategy.atMost(340).build();
Expand Down Expand Up @@ -147,7 +146,7 @@ class VideoCompressPlugin : MethodCallHandler, FlutterPlugin {
}


transcodeFuture = Transcoder.into(destPath!!)
transcodeFuture = Transcoder.into(destPath)
.addDataSource(dataSource)
.setAudioTrackStrategy(audioTrackStrategy)
.setVideoTrackStrategy(videoTrackStrategy)
Expand Down
2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
Expand Down Expand Up @@ -61,6 +62,7 @@
**/ios/Flutter/flutter_assets/
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*
**/ios/Flutter/flutter_export_environment.sh

# Exceptions to above rules.
!**/ios/**/default.mode1v3
Expand Down