do not use java 8 features in flutter, fixes #200

This commit is contained in:
Taner Sener 2021-10-25 23:57:09 +01:00
parent afa1a19859
commit fcd00c6850

View File

@ -23,6 +23,7 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -57,12 +58,11 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware; import io.flutter.embedding.engine.plugins.activity.ActivityAware;
@ -249,72 +249,72 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
@Override @Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
final Optional<Integer> sessionIdOptional = Optional.ofNullable(call.argument(ARGUMENT_SESSION_ID)); final Integer sessionId = call.argument(ARGUMENT_SESSION_ID);
final Integer waitTimeout = call.argument(ARGUMENT_WAIT_TIMEOUT); final Integer waitTimeout = call.argument(ARGUMENT_WAIT_TIMEOUT);
final Optional<List<String>> argumentsOptional = Optional.ofNullable(call.argument(ARGUMENT_ARGUMENTS)); final List<String> arguments = call.argument(ARGUMENT_ARGUMENTS);
final Optional<String> ffprobeJsonOutputOptional = Optional.ofNullable(call.argument(ARGUMENT_FFPROBE_JSON_OUTPUT)); final String ffprobeJsonOutput = call.argument(ARGUMENT_FFPROBE_JSON_OUTPUT);
final Optional<Boolean> writableOptional = Optional.ofNullable(call.argument(ARGUMENT_WRITABLE)); final Boolean writable = call.argument(ARGUMENT_WRITABLE);
switch (call.method) { switch (call.method) {
case "abstractSessionGetEndTime": case "abstractSessionGetEndTime":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
abstractSessionGetEndTime(sessionIdOptional.get(), result); abstractSessionGetEndTime(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
break; break;
case "abstractSessionGetDuration": case "abstractSessionGetDuration":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
abstractSessionGetDuration(sessionIdOptional.get(), result); abstractSessionGetDuration(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
break; break;
case "abstractSessionGetAllLogs": case "abstractSessionGetAllLogs":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
abstractSessionGetAllLogs(sessionIdOptional.get(), waitTimeout, result); abstractSessionGetAllLogs(sessionId, waitTimeout, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
break; break;
case "abstractSessionGetLogs": case "abstractSessionGetLogs":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
abstractSessionGetLogs(sessionIdOptional.get(), result); abstractSessionGetLogs(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
break; break;
case "abstractSessionGetAllLogsAsString": case "abstractSessionGetAllLogsAsString":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
abstractSessionGetAllLogsAsString(sessionIdOptional.get(), waitTimeout, result); abstractSessionGetAllLogsAsString(sessionId, waitTimeout, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
break; break;
case "abstractSessionGetState": case "abstractSessionGetState":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
abstractSessionGetState(sessionIdOptional.get(), result); abstractSessionGetState(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
break; break;
case "abstractSessionGetReturnCode": case "abstractSessionGetReturnCode":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
abstractSessionGetReturnCode(sessionIdOptional.get(), result); abstractSessionGetReturnCode(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
break; break;
case "abstractSessionGetFailStackTrace": case "abstractSessionGetFailStackTrace":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
abstractSessionGetFailStackTrace(sessionIdOptional.get(), result); abstractSessionGetFailStackTrace(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
break; break;
case "thereAreAsynchronousMessagesInTransmit": case "thereAreAsynchronousMessagesInTransmit":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
abstractSessionThereAreAsynchronousMessagesInTransmit(sessionIdOptional.get(), result); abstractSessionThereAreAsynchronousMessagesInTransmit(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
@ -323,50 +323,50 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
getArch(result); getArch(result);
break; break;
case "ffmpegSession": case "ffmpegSession":
if (argumentsOptional.isPresent()) { if (arguments != null) {
ffmpegSession(argumentsOptional.get(), result); ffmpegSession(arguments, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_ARGUMENTS", "Invalid arguments array."); resultHandler.errorAsync(result, "INVALID_ARGUMENTS", "Invalid arguments array.");
} }
break; break;
case "ffmpegSessionGetAllStatistics": case "ffmpegSessionGetAllStatistics":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
ffmpegSessionGetAllStatistics(sessionIdOptional.get(), waitTimeout, result); ffmpegSessionGetAllStatistics(sessionId, waitTimeout, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
break; break;
case "ffmpegSessionGetStatistics": case "ffmpegSessionGetStatistics":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
ffmpegSessionGetStatistics(sessionIdOptional.get(), result); ffmpegSessionGetStatistics(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
break; break;
case "ffprobeSession": case "ffprobeSession":
if (argumentsOptional.isPresent()) { if (arguments != null) {
ffprobeSession(argumentsOptional.get(), result); ffprobeSession(arguments, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_ARGUMENTS", "Invalid arguments array."); resultHandler.errorAsync(result, "INVALID_ARGUMENTS", "Invalid arguments array.");
} }
break; break;
case "mediaInformationSession": case "mediaInformationSession":
if (argumentsOptional.isPresent()) { if (arguments != null) {
mediaInformationSession(argumentsOptional.get(), result); mediaInformationSession(arguments, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_ARGUMENTS", "Invalid arguments array."); resultHandler.errorAsync(result, "INVALID_ARGUMENTS", "Invalid arguments array.");
} }
break; break;
case "mediaInformationJsonParserFrom": case "mediaInformationJsonParserFrom":
if (ffprobeJsonOutputOptional.isPresent()) { if (ffprobeJsonOutput != null) {
mediaInformationJsonParserFrom(ffprobeJsonOutputOptional.get(), result); mediaInformationJsonParserFrom(ffprobeJsonOutput, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_FFPROBE_JSON_OUTPUT", "Invalid ffprobe json output."); resultHandler.errorAsync(result, "INVALID_FFPROBE_JSON_OUTPUT", "Invalid ffprobe json output.");
} }
break; break;
case "mediaInformationJsonParserFromWithError": case "mediaInformationJsonParserFromWithError":
if (ffprobeJsonOutputOptional.isPresent()) { if (ffprobeJsonOutput != null) {
mediaInformationJsonParserFromWithError(ffprobeJsonOutputOptional.get(), result); mediaInformationJsonParserFromWithError(ffprobeJsonOutput, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_FFPROBE_JSON_OUTPUT", "Invalid ffprobe json output."); resultHandler.errorAsync(result, "INVALID_FFPROBE_JSON_OUTPUT", "Invalid ffprobe json output.");
} }
@ -390,28 +390,28 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
disableStatistics(result); disableStatistics(result);
break; break;
case "setFontconfigConfigurationPath": case "setFontconfigConfigurationPath":
final Optional<String> pathOptional = Optional.ofNullable(call.argument("path")); final String path = call.argument("path");
if (pathOptional.isPresent()) { if (path != null) {
setFontconfigConfigurationPath(pathOptional.get(), result); setFontconfigConfigurationPath(path, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_PATH", "Invalid path."); resultHandler.errorAsync(result, "INVALID_PATH", "Invalid path.");
} }
break; break;
case "setFontDirectory": { case "setFontDirectory": {
final Optional<String> fontDirectoryOptional = Optional.ofNullable(call.argument("fontDirectory")); final String fontDirectory = call.argument("fontDirectory");
final Map<String, String> fontNameMap = call.argument("fontNameMap"); final Map<String, String> fontNameMap = call.argument("fontNameMap");
if (fontDirectoryOptional.isPresent()) { if (fontDirectory != null) {
setFontDirectory(fontDirectoryOptional.get(), fontNameMap, result); setFontDirectory(fontDirectory, fontNameMap, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_FONT_DIRECTORY", "Invalid font directory."); resultHandler.errorAsync(result, "INVALID_FONT_DIRECTORY", "Invalid font directory.");
} }
break; break;
} }
case "setFontDirectoryList": { case "setFontDirectoryList": {
final Optional<List<String>> fontDirectoryListOptional = Optional.ofNullable(call.argument("fontDirectoryList")); final List<String> fontDirectoryList = call.argument("fontDirectoryList");
final Map<String, String> fontNameMap = call.argument("fontNameMap"); final Map<String, String> fontNameMap = call.argument("fontNameMap");
if (fontDirectoryListOptional.isPresent()) { if (fontDirectoryList != null) {
setFontDirectoryList(fontDirectoryListOptional.get(), fontNameMap, result); setFontDirectoryList(fontDirectoryList, fontNameMap, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_FONT_DIRECTORY_LIST", "Invalid font directory list."); resultHandler.errorAsync(result, "INVALID_FONT_DIRECTORY_LIST", "Invalid font directory list.");
} }
@ -421,9 +421,9 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
registerNewFFmpegPipe(result); registerNewFFmpegPipe(result);
break; break;
case "closeFFmpegPipe": case "closeFFmpegPipe":
final Optional<String> ffmpegPipePathOptional = Optional.ofNullable(call.argument("ffmpegPipePath")); final String ffmpegPipePath = call.argument("ffmpegPipePath");
if (ffmpegPipePathOptional.isPresent()) { if (ffmpegPipePath != null) {
closeFFmpegPipe(ffmpegPipePathOptional.get(), result); closeFFmpegPipe(ffmpegPipePath, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_PIPE_PATH", "Invalid ffmpeg pipe path."); resultHandler.errorAsync(result, "INVALID_PIPE_PATH", "Invalid ffmpeg pipe path.");
} }
@ -438,42 +438,42 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
getBuildDate(result); getBuildDate(result);
break; break;
case "setEnvironmentVariable": case "setEnvironmentVariable":
final Optional<String> variableNameOptional = Optional.ofNullable(call.argument("variableName")); final String variableName = call.argument("variableName");
final Optional<String> variableValueOptional = Optional.ofNullable(call.argument("variableValue")); final String variableValue = call.argument("variableValue");
if (variableNameOptional.isPresent() && variableValueOptional.isPresent()) { if (variableName != null && variableValue != null) {
setEnvironmentVariable(variableNameOptional.get(), variableValueOptional.get(), result); setEnvironmentVariable(variableName, variableValue, result);
} else if (variableValueOptional.isPresent()) { } else if (variableValue != null) {
resultHandler.errorAsync(result, "INVALID_NAME", "Invalid environment variable name."); resultHandler.errorAsync(result, "INVALID_NAME", "Invalid environment variable name.");
} else { } else {
resultHandler.errorAsync(result, "INVALID_VALUE", "Invalid environment variable value."); resultHandler.errorAsync(result, "INVALID_VALUE", "Invalid environment variable value.");
} }
break; break;
case "ignoreSignal": case "ignoreSignal":
final Optional<Integer> signalOptional = Optional.ofNullable(call.argument("signal")); final Integer signal = call.argument("signal");
if (signalOptional.isPresent()) { if (signal != null) {
ignoreSignal(signalOptional.get(), result); ignoreSignal(signal, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SIGNAL", "Invalid signal value."); resultHandler.errorAsync(result, "INVALID_SIGNAL", "Invalid signal value.");
} }
break; break;
case "asyncFFmpegSessionExecute": case "asyncFFmpegSessionExecute":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
asyncFFmpegSessionExecute(sessionIdOptional.get(), result); asyncFFmpegSessionExecute(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
break; break;
case "asyncFFprobeSessionExecute": case "asyncFFprobeSessionExecute":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
asyncFFprobeSessionExecute(sessionIdOptional.get(), result); asyncFFprobeSessionExecute(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
break; break;
case "asyncMediaInformationSessionExecute": case "asyncMediaInformationSessionExecute":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
asyncMediaInformationSessionExecute(sessionIdOptional.get(), waitTimeout, result); asyncMediaInformationSessionExecute(sessionId, waitTimeout, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
@ -482,9 +482,9 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
getLogLevel(result); getLogLevel(result);
break; break;
case "setLogLevel": case "setLogLevel":
final Optional<Integer> levelOptional = Optional.ofNullable(call.argument("level")); final Integer level = call.argument("level");
if (levelOptional.isPresent()) { if (level != null) {
setLogLevel(levelOptional.get(), result); setLogLevel(level, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_LEVEL", "Invalid level value."); resultHandler.errorAsync(result, "INVALID_LEVEL", "Invalid level value.");
} }
@ -493,16 +493,16 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
getSessionHistorySize(result); getSessionHistorySize(result);
break; break;
case "setSessionHistorySize": case "setSessionHistorySize":
final Optional<Integer> sessionHistorySizeOptional = Optional.ofNullable(call.argument("sessionHistorySize")); final Integer sessionHistorySize = call.argument("sessionHistorySize");
if (sessionHistorySizeOptional.isPresent()) { if (sessionHistorySize != null) {
setSessionHistorySize(sessionHistorySizeOptional.get(), result); setSessionHistorySize(sessionHistorySize, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SIZE", "Invalid session history size value."); resultHandler.errorAsync(result, "INVALID_SIZE", "Invalid session history size value.");
} }
break; break;
case "getSession": case "getSession":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
getSession(sessionIdOptional.get(), result); getSession(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
@ -520,9 +520,9 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
clearSessions(result); clearSessions(result);
break; break;
case "getSessionsByState": case "getSessionsByState":
final Optional<Integer> stateOptional = Optional.ofNullable(call.argument("state")); final Integer state = call.argument("state");
if (stateOptional.isPresent()) { if (state != null) {
getSessionsByState(stateOptional.get(), result); getSessionsByState(state, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION_STATE", "Invalid session state value."); resultHandler.errorAsync(result, "INVALID_SESSION_STATE", "Invalid session state value.");
} }
@ -531,16 +531,16 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
getLogRedirectionStrategy(result); getLogRedirectionStrategy(result);
break; break;
case "setLogRedirectionStrategy": case "setLogRedirectionStrategy":
final Optional<Integer> strategyOptional = Optional.ofNullable(call.argument("strategy")); final Integer strategy = call.argument("strategy");
if (strategyOptional.isPresent()) { if (strategy != null) {
setLogRedirectionStrategy(strategyOptional.get(), result); setLogRedirectionStrategy(strategy, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_LOG_REDIRECTION_STRATEGY", "Invalid log redirection strategy value."); resultHandler.errorAsync(result, "INVALID_LOG_REDIRECTION_STRATEGY", "Invalid log redirection strategy value.");
} }
break; break;
case "messagesInTransmit": case "messagesInTransmit":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
messagesInTransmit(sessionIdOptional.get(), result); messagesInTransmit(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
@ -549,11 +549,11 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
getPlatform(result); getPlatform(result);
break; break;
case "writeToPipe": case "writeToPipe":
final Optional<String> inputOptional = Optional.ofNullable(call.argument("input")); final String input = call.argument("input");
final Optional<String> pipeOptional = Optional.ofNullable(call.argument("pipe")); final String pipe = call.argument("pipe");
if (inputOptional.isPresent() && pipeOptional.isPresent()) { if (input != null && pipe != null) {
writeToPipe(inputOptional.get(), pipeOptional.get(), result); writeToPipe(input, pipe, result);
} else if (pipeOptional.isPresent()) { } else if (pipe != null) {
resultHandler.errorAsync(result, "INVALID_INPUT", "Invalid input value."); resultHandler.errorAsync(result, "INVALID_INPUT", "Invalid input value.");
} else { } else {
resultHandler.errorAsync(result, "INVALID_PIPE", "Invalid pipe value."); resultHandler.errorAsync(result, "INVALID_PIPE", "Invalid pipe value.");
@ -562,19 +562,24 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
case "selectDocument": case "selectDocument":
final String title = call.argument("title"); final String title = call.argument("title");
final String type = call.argument("type"); final String type = call.argument("type");
final Optional<List<String>> extraTypesOptional = Optional.ofNullable(call.argument("extraTypes")); final List<String> extraTypes = call.argument("extraTypes");
final String[] extraTypesArray = extraTypesOptional.map(strings -> strings.toArray(new String[0])).orElse(null); final String[] extraTypesArray;
if (writableOptional.isPresent()) { if (extraTypes != null) {
selectDocument(writableOptional.get(), title, type, extraTypesArray, result); extraTypesArray = extraTypes.toArray(new String[0]);
} else {
extraTypesArray = null;
}
if (writable != null) {
selectDocument(writable, title, type, extraTypesArray, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_WRITABLE", "Invalid writable value."); resultHandler.errorAsync(result, "INVALID_WRITABLE", "Invalid writable value.");
} }
break; break;
case "getSafParameter": case "getSafParameter":
final Optional<String> uriOptional = Optional.ofNullable(call.argument("uri")); final String uri = call.argument("uri");
if (writableOptional.isPresent() && uriOptional.isPresent()) { if (writable != null && uri != null) {
getSafParameter(writableOptional.get(), uriOptional.get(), result); getSafParameter(writable, uri, result);
} else if (uriOptional.isPresent()) { } else if (uri != null) {
resultHandler.errorAsync(result, "INVALID_WRITABLE", "Invalid writable value."); resultHandler.errorAsync(result, "INVALID_WRITABLE", "Invalid writable value.");
} else { } else {
resultHandler.errorAsync(result, "INVALID_URI", "Invalid uri value."); resultHandler.errorAsync(result, "INVALID_URI", "Invalid uri value.");
@ -584,8 +589,8 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
cancel(result); cancel(result);
break; break;
case "cancelSession": case "cancelSession":
if (sessionIdOptional.isPresent()) { if (sessionId != null) {
cancelSession(sessionIdOptional.get(), result); cancelSession(sessionId, result);
} else { } else {
resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id."); resultHandler.errorAsync(result, "INVALID_SESSION", "Invalid session id.");
} }
@ -711,7 +716,7 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
timeout = AbstractSession.DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT; timeout = AbstractSession.DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT;
} }
final List<com.arthenica.ffmpegkit.Log> allLogs = session.getAllLogs(timeout); final List<com.arthenica.ffmpegkit.Log> allLogs = session.getAllLogs(timeout);
resultHandler.successAsync(result, allLogs.stream().map(FFmpegKitFlutterPlugin::toMap).collect(Collectors.toList())); resultHandler.successAsync(result, toLogMapList(allLogs));
} }
} }
@ -721,7 +726,7 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
resultHandler.errorAsync(result, "SESSION_NOT_FOUND", "Session not found."); resultHandler.errorAsync(result, "SESSION_NOT_FOUND", "Session not found.");
} else { } else {
final List<com.arthenica.ffmpegkit.Log> allLogs = session.getLogs(); final List<com.arthenica.ffmpegkit.Log> allLogs = session.getLogs();
resultHandler.successAsync(result, allLogs.stream().map(FFmpegKitFlutterPlugin::toMap).collect(Collectors.toList())); resultHandler.successAsync(result, toLogMapList(allLogs));
} }
} }
@ -808,7 +813,7 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
timeout = AbstractSession.DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT; timeout = AbstractSession.DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT;
} }
final List<Statistics> allStatistics = ((FFmpegSession) session).getAllStatistics(timeout); final List<Statistics> allStatistics = ((FFmpegSession) session).getAllStatistics(timeout);
resultHandler.successAsync(result, allStatistics.stream().map(FFmpegKitFlutterPlugin::toMap).collect(Collectors.toList())); resultHandler.successAsync(result, toStatisticsMapList(allStatistics));
} else { } else {
resultHandler.errorAsync(result, "NOT_FFMPEG_SESSION", "A session is found but it does not have the correct type."); resultHandler.errorAsync(result, "NOT_FFMPEG_SESSION", "A session is found but it does not have the correct type.");
} }
@ -822,7 +827,7 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
} else { } else {
if (session instanceof FFmpegSession) { if (session instanceof FFmpegSession) {
final List<Statistics> statistics = ((FFmpegSession) session).getStatistics(); final List<Statistics> statistics = ((FFmpegSession) session).getStatistics();
resultHandler.successAsync(result, statistics.stream().map(FFmpegKitFlutterPlugin::toMap).collect(Collectors.toList())); resultHandler.successAsync(result, toStatisticsMapList(statistics));
} else { } else {
resultHandler.errorAsync(result, "NOT_FFMPEG_SESSION", "A session is found but it does not have the correct type."); resultHandler.errorAsync(result, "NOT_FFMPEG_SESSION", "A session is found but it does not have the correct type.");
} }
@ -1074,7 +1079,7 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
} }
protected void getSessions(@NonNull final Result result) { protected void getSessions(@NonNull final Result result) {
resultHandler.successAsync(result, toSessionArray(FFmpegKitConfig.getSessions())); resultHandler.successAsync(result, toSessionMapList(FFmpegKitConfig.getSessions()));
} }
protected void clearSessions(@NonNull final Result result) { protected void clearSessions(@NonNull final Result result) {
@ -1083,7 +1088,7 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
} }
protected void getSessionsByState(@NonNull final Integer sessionState, @NonNull final Result result) { protected void getSessionsByState(@NonNull final Integer sessionState, @NonNull final Result result) {
resultHandler.successAsync(result, toSessionArray(FFmpegKitConfig.getSessionsByState(toSessionState(sessionState)))); resultHandler.successAsync(result, toSessionMapList(FFmpegKitConfig.getSessionsByState(toSessionState(sessionState))));
} }
protected void getLogRedirectionStrategy(@NonNull final Result result) { protected void getLogRedirectionStrategy(@NonNull final Result result) {
@ -1109,6 +1114,12 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
} }
protected void selectDocument(@NonNull final Boolean writable, @Nullable final String title, @Nullable final String type, @Nullable final String[] extraTypes, @NonNull final Result result) { protected void selectDocument(@NonNull final Boolean writable, @Nullable final String title, @Nullable final String type, @Nullable final String[] extraTypes, @NonNull final Result result) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
android.util.Log.i(LIBRARY_NAME, String.format(Locale.getDefault(), "selectDocument is not supported on API Level %d", Build.VERSION.SDK_INT));
resultHandler.errorAsync(result, "SELECT_FAILED", String.format(Locale.getDefault(), "selectDocument is not supported on API Level %d", Build.VERSION.SDK_INT));
return;
}
final Intent intent; final Intent intent;
if (writable) { if (writable) {
intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
@ -1153,6 +1164,12 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
} }
protected void getSafParameter(@NonNull final Boolean writable, @NonNull final String uriString, @NonNull final Result result) { protected void getSafParameter(@NonNull final Boolean writable, @NonNull final String uriString, @NonNull final Result result) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
android.util.Log.i(LIBRARY_NAME, String.format(Locale.getDefault(), "getSafParameter is not supported on API Level %d", Build.VERSION.SDK_INT));
resultHandler.errorAsync(result, "SELECT_FAILED", String.format(Locale.getDefault(), "getSafParameter is not supported on API Level %d", Build.VERSION.SDK_INT));
return;
}
if (context != null) { if (context != null) {
final Uri uri = Uri.parse(uriString); final Uri uri = Uri.parse(uriString);
if (uri == null) { if (uri == null) {
@ -1189,13 +1206,13 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
} }
protected void getFFmpegSessions(@NonNull final Result result) { protected void getFFmpegSessions(@NonNull final Result result) {
resultHandler.successAsync(result, toSessionArray(FFmpegKit.listSessions())); resultHandler.successAsync(result, toSessionMapList(FFmpegKit.listSessions()));
} }
// FFprobeKit // FFprobeKit
protected void getFFprobeSessions(@NonNull final Result result) { protected void getFFprobeSessions(@NonNull final Result result) {
resultHandler.successAsync(result, toSessionArray(FFprobeKit.listSessions())); resultHandler.successAsync(result, toSessionMapList(FFprobeKit.listSessions()));
} }
// Packages // Packages
@ -1339,16 +1356,6 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
return statisticsMap; return statisticsMap;
} }
protected static List<Map<String, Object>> toSessionArray(final List<? extends Session> sessions) {
final List<Map<String, Object>> sessionArray = new ArrayList<>();
for (int i = 0; i < sessions.size(); i++) {
sessionArray.add(toMap(sessions.get(i)));
}
return sessionArray;
}
protected static Map<String, Object> toMap(final MediaInformation mediaInformation) { protected static Map<String, Object> toMap(final MediaInformation mediaInformation) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
@ -1404,6 +1411,36 @@ public class FFmpegKitFlutterPlugin implements FlutterPlugin, ActivityAware, Met
return list; return list;
} }
protected static List<Map<String, Object>> toSessionMapList(final List<? extends Session> sessionList) {
final List<Map<String, Object>> list = new ArrayList<>();
for (int i = 0; i < sessionList.size(); i++) {
list.add(toMap(sessionList.get(i)));
}
return list;
}
protected static List<Map<String, Object>> toLogMapList(final List<com.arthenica.ffmpegkit.Log> logList) {
final List<Map<String, Object>> list = new ArrayList<>();
for (int i = 0; i < logList.size(); i++) {
list.add(toMap(logList.get(i)));
}
return list;
}
protected static List<Map<String, Object>> toStatisticsMapList(final List<com.arthenica.ffmpegkit.Statistics> statisticsList) {
final List<Map<String, Object>> list = new ArrayList<>();
for (int i = 0; i < statisticsList.size(); i++) {
list.add(toMap(statisticsList.get(i)));
}
return list;
}
protected static boolean isValidPositiveNumber(final Integer value) { protected static boolean isValidPositiveNumber(final Integer value) {
return (value != null) && (value >= 0); return (value != null) && (value >= 0);
} }