change ThreadPootlUtil to kotlin

pull/166/head
xufuji456 4 years ago
parent b78bd398ea
commit 07894efd45
  1. 6
      app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java
  2. 4
      app/src/main/java/com/frank/ffmpeg/activity/MediaHandleActivity.kt
  3. 4
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  4. 53
      app/src/main/java/com/frank/ffmpeg/util/ScreenUtil.java
  5. 50
      app/src/main/java/com/frank/ffmpeg/util/ScreenUtil.kt
  6. 14
      app/src/main/java/com/frank/ffmpeg/util/ThreadPoolUtil.java
  7. 14
      app/src/main/java/com/frank/ffmpeg/util/ThreadPoolUtil.kt
  8. 2
      app/src/main/java/com/frank/ffmpeg/view/VideoPreviewBar.java

@ -49,7 +49,7 @@ public class FFmpegCmd {
*/
public static void execute(final String[] commands, final OnHandleListener onHandleListener) {
mProgressListener = onHandleListener;
ThreadPoolUtil.executeSingleThreadPool(new Runnable() {
ThreadPoolUtil.INSTANCE.executeSingleThreadPool(new Runnable() {
@Override
public void run() {
if (onHandleListener != null) {
@ -76,7 +76,7 @@ public class FFmpegCmd {
*/
public static void execute(final List<String[]> commands, final OnHandleListener onHandleListener) {
mProgressListener = onHandleListener;
ThreadPoolUtil.executeSingleThreadPool(new Runnable() {
ThreadPoolUtil.INSTANCE.executeSingleThreadPool(new Runnable() {
@Override
public void run() {
if (onHandleListener != null) {
@ -124,7 +124,7 @@ public class FFmpegCmd {
* @param onHandleListener onHandleListener
*/
public static void executeProbe(final String[] commands, final OnHandleListener onHandleListener) {
ThreadPoolUtil.executeSingleThreadPool(new Runnable() {
ThreadPoolUtil.INSTANCE.executeSingleThreadPool(new Runnable() {
@Override
public void run() {
if (onHandleListener != null) {

@ -115,7 +115,7 @@ class MediaHandleActivity : BaseActivity() {
when (viewId) {
R.id.btn_mux//mux:pure video and pure audio
-> {
ThreadPoolUtil.executeSingleThreadPool { mediaMux(srcFile) }
ThreadPoolUtil.executeSingleThreadPool (Runnable { mediaMux(srcFile) })
return
}
R.id.btn_extract_audio//extract audio
@ -130,7 +130,7 @@ class MediaHandleActivity : BaseActivity() {
}
R.id.btn_dubbing//dubbing
-> {
ThreadPoolUtil.executeSingleThreadPool { mediaDubbing(srcFile) }
ThreadPoolUtil.executeSingleThreadPool (Runnable{ mediaDubbing(srcFile) })
return
}
else -> {

@ -252,7 +252,7 @@ public class FFmpegUtil {
public static String[] addWaterMarkImg(String inputPath, String imgPath, int location, int bitRate,
int offsetXY, String outputPath) {
String mBitRate = bitRate + "k";
int offset = ScreenUtil.dp2px(FFmpegApplication.getInstance(), offsetXY);
int offset = ScreenUtil.INSTANCE.dp2px(FFmpegApplication.getInstance(), offsetXY);
String overlay = obtainOverlay(offset, offset, location);
String waterMarkCmd = "ffmpeg -i %s -i %s -b:v %s -filter_complex %s -preset:v superfast %s";
waterMarkCmd = String.format(waterMarkCmd, inputPath, imgPath, mBitRate, overlay, outputPath);
@ -273,7 +273,7 @@ public class FFmpegUtil {
public static String[] addWaterMarkGif(String inputPath, String imgPath, int location, int bitRate,
int offsetXY, String outputPath) {
String mBitRate = bitRate + "k";
int offset = ScreenUtil.dp2px(FFmpegApplication.getInstance(), offsetXY);
int offset = ScreenUtil.INSTANCE.dp2px(FFmpegApplication.getInstance(), offsetXY);
String overlay = obtainOverlay(offset, offset, location) + ":shortest=1";
String waterMarkCmd = "ffmpeg -i %s -ignore_loop 0 -i %s -b:v %s -filter_complex %s -preset:v superfast %s";
waterMarkCmd = String.format(waterMarkCmd, inputPath, imgPath, mBitRate, overlay, outputPath);

@ -1,53 +0,0 @@
package com.frank.ffmpeg.util;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;
public class ScreenUtil {
private static DisplayMetrics getDisplayMetrics(Context context) {
WindowManager windowManager = (WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
if (windowManager == null) {
return null;
}
DisplayMetrics displayMetrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics;
}
public static int getScreenWidth(Context context) {
if (context == null) {
return 0;
}
DisplayMetrics displayMetrics = getDisplayMetrics(context);
return displayMetrics != null ? displayMetrics.widthPixels : 0;
}
public static int getScreenHeight(Context context) {
if (context == null) {
return 0;
}
DisplayMetrics displayMetrics = getDisplayMetrics(context);
return displayMetrics != null ? displayMetrics.heightPixels : 0;
}
public static int dp2px(Context context, int dpValue) {
if (context == null) {
return 0;
}
DisplayMetrics displayMetrics = getDisplayMetrics(context);
float density = displayMetrics != null ? displayMetrics.density : 0;
return (int) (dpValue * density + 0.5f);
}
public static int px2dp(Context context, int pxValue) {
if (context == null) {
return 0;
}
DisplayMetrics displayMetrics = getDisplayMetrics(context);
float density = displayMetrics != null ? displayMetrics.density : 0;
return (int) (pxValue / density + 0.5f);
}
}

@ -0,0 +1,50 @@
package com.frank.ffmpeg.util
import android.content.Context
import android.util.DisplayMetrics
import android.view.WindowManager
object ScreenUtil {
private fun getDisplayMetrics(context: Context): DisplayMetrics? {
val windowManager = context.applicationContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
return displayMetrics
}
fun getScreenWidth(context: Context?): Int {
if (context == null) {
return 0
}
val displayMetrics = getDisplayMetrics(context)
return displayMetrics?.widthPixels ?: 0
}
fun getScreenHeight(context: Context?): Int {
if (context == null) {
return 0
}
val displayMetrics = getDisplayMetrics(context)
return displayMetrics?.heightPixels ?: 0
}
fun dp2px(context: Context?, dpValue: Int): Int {
if (context == null) {
return 0
}
val displayMetrics = getDisplayMetrics(context)
val density: Float = displayMetrics?.density ?: 0F
return (dpValue * density + 0.5f).toInt()
}
fun px2dp(context: Context?, pxValue: Int): Int {
if (context == null) {
return 0
}
val displayMetrics = getDisplayMetrics(context)
val density: Float = displayMetrics?.density ?: 0F
return (pxValue / density + 0.5f).toInt()
}
}

@ -1,14 +0,0 @@
package com.frank.ffmpeg.util;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadPoolUtil {
public static ExecutorService executeSingleThreadPool(Runnable runnable) {
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(runnable);
return executor;
}
}

@ -0,0 +1,14 @@
package com.frank.ffmpeg.util
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
object ThreadPoolUtil {
fun executeSingleThreadPool(runnable: Runnable): ExecutorService {
val executor = Executors.newSingleThreadExecutor()
executor.submit(runnable)
return executor
}
}

@ -64,7 +64,7 @@ public class VideoPreviewBar extends RelativeLayout implements HardwareDecode.On
txtVideoProgress = view.findViewById(R.id.txt_video_progress);
txtVideoDuration = view.findViewById(R.id.txt_video_duration);
setListener();
screenWidth = ScreenUtil.getScreenWidth(context);
screenWidth = ScreenUtil.INSTANCE.getScreenWidth(context);
}
@Override

Loading…
Cancel
Save