Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit eaa0b91

Browse files
committed
fix execute() methods
1 parent 8448f29 commit eaa0b91

File tree

4 files changed

+74
-38
lines changed

4 files changed

+74
-38
lines changed

react-native/android/src/main/java/com/arthenica/ffmpegkit/reactnative/FFmpegKitReactNativeModule.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,32 @@ public void getMediaInformationSessions(final Promise promise) {
946946
promise.resolve(toSessionArray(FFprobeKit.listMediaInformationSessions()));
947947
}
948948

949+
// MediaInformationSession
950+
951+
@ReactMethod
952+
public void getMediaInformation(final Double sessionId, final Promise promise) {
953+
if (sessionId != null) {
954+
final Session session = FFmpegKitConfig.getSession(sessionId.longValue());
955+
if (session == null) {
956+
promise.reject("SESSION_NOT_FOUND", "Session not found.");
957+
} else {
958+
if (session.isMediaInformation()) {
959+
final MediaInformationSession mediaInformationSession = (MediaInformationSession) session;
960+
final MediaInformation mediaInformation = mediaInformationSession.getMediaInformation();
961+
if (mediaInformation != null) {
962+
promise.resolve(toMap(mediaInformation));
963+
} else {
964+
promise.resolve(null);
965+
}
966+
} else {
967+
promise.reject("NOT_MEDIA_INFORMATION_SESSION", "A session is found but it does not have the correct type.");
968+
}
969+
}
970+
} else {
971+
promise.reject("INVALID_SESSION", "Invalid session id.");
972+
}
973+
}
974+
949975
// Packages
950976

951977
@ReactMethod

react-native/ios/FFmpegKitReactNativeModule.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,22 @@ - (void)registerGlobalCallbacks {
669669
resolve([FFmpegKitReactNativeModule toSessionArray:[FFprobeKit listMediaInformationSessions]]);
670670
}
671671

672+
// MediaInformationSession
673+
674+
RCT_EXPORT_METHOD(getMediaInformation:(int)sessionId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
675+
AbstractSession* session = (AbstractSession*)[FFmpegKitConfig getSession:sessionId];
676+
if (session == nil) {
677+
reject(@"SESSION_NOT_FOUND", @"Session not found.", nil);
678+
} else {
679+
if ([session isMediaInformation]) {
680+
MediaInformationSession *mediaInformationSession = (MediaInformationSession*)session;
681+
resolve([FFmpegKitReactNativeModule toMediaInformationDictionary:[mediaInformationSession getMediaInformation]]);
682+
} else {
683+
reject(@"NOT_MEDIA_INFORMATION_SESSION", @"A session is found but it does not have the correct type.", nil);
684+
}
685+
}
686+
}
687+
672688
// Packages
673689

674690
RCT_EXPORT_METHOD(getPackageName:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {

react-native/src/index.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ declare module 'ffmpeg-kit-react-native' {
7474

7575
export class FFmpegKit {
7676

77-
static execute(command: string, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
77+
static execute(command: string): Promise<FFmpegSession>;
7878

79-
static executeWithArguments(commandArguments: string[], completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
79+
static executeWithArguments(commandArguments: string[]): Promise<FFmpegSession>;
8080

8181
static executeAsync(command: string, completeCallback?: FFmpegSessionCompleteCallback, logCallback?: LogCallback, statisticsCallback?: StatisticsCallback): Promise<FFmpegSession>;
8282

@@ -236,19 +236,19 @@ declare module 'ffmpeg-kit-react-native' {
236236

237237
export class FFprobeKit {
238238

239-
static execute(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
239+
static execute(command: string): Promise<FFprobeSession>;
240240

241-
static executeWithArguments(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
241+
static executeWithArguments(commandArguments: string[]): Promise<FFprobeSession>;
242242

243243
static executeAsync(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
244244

245245
static executeWithArgumentsAsync(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback): Promise<FFprobeSession>;
246246

247-
static getMediaInformation(path: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
247+
static getMediaInformation(path: string, waitTimeout?: number): Promise<MediaInformationSession>;
248248

249-
static getMediaInformationFromCommand(command: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
249+
static getMediaInformationFromCommand(command: string, waitTimeout?: number): Promise<MediaInformationSession>;
250250

251-
static getMediaInformationFromCommandArguments(commandArguments: string[], completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
251+
static getMediaInformationFromCommandArguments(commandArguments: string[], waitTimeout?: number): Promise<MediaInformationSession>;
252252

253253
static getMediaInformationAsync(path: string, completeCallback?: FFprobeSessionCompleteCallback, logCallback?: LogCallback, waitTimeout?: number): Promise<MediaInformationSession>;
254254

react-native/src/index.js

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -709,26 +709,20 @@ export class FFmpegKit {
709709
* into arguments. You can use single or double quote characters to specify arguments inside your command.
710710
*
711711
* @param command FFmpeg command
712-
* @param completeCallback callback that will be called when the execution has completed
713-
* @param logCallback callback that will receive logs
714-
* @param statisticsCallback callback that will receive statistics
715712
* @return FFmpeg session created for this execution
716713
*/
717-
static async execute(command, completeCallback, logCallback, statisticsCallback) {
718-
return FFmpegKit.executeWithArguments(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, statisticsCallback);
714+
static async execute(command) {
715+
return FFmpegKit.executeWithArguments(FFmpegKitConfig.parseArguments(command));
719716
}
720717

721718
/**
722719
* <p>Synchronously executes FFmpeg with arguments provided.
723720
*
724721
* @param commandArguments FFmpeg command options/arguments as string array
725-
* @param completeCallback callback that will be called when the execution has completed
726-
* @param logCallback callback that will receive logs
727-
* @param statisticsCallback callback that will receive statistics
728722
* @return FFmpeg session created for this execution
729723
*/
730-
static async executeWithArguments(commandArguments, completeCallback, logCallback, statisticsCallback) {
731-
let session = await FFmpegSession.create(commandArguments, completeCallback, logCallback, statisticsCallback);
724+
static async executeWithArguments(commandArguments) {
725+
let session = await FFmpegSession.create(commandArguments, undefined, undefined, undefined);
732726

733727
await FFmpegKitConfig.ffmpegExecute(session);
734728

@@ -1614,7 +1608,7 @@ class FFmpegKitFactory {
16141608
}
16151609

16161610
static getVersion() {
1617-
return "4.5";
1611+
return "4.5.1";
16181612
}
16191613

16201614
static getLogRedirectionStrategy(sessionId) {
@@ -2055,24 +2049,20 @@ export class FFprobeKit {
20552049
* into arguments. You can use single or double quote characters to specify arguments inside your command.
20562050
*
20572051
* @param command FFprobe command
2058-
* @param completeCallback callback that will be called when the execution has completed
2059-
* @param logCallback callback that will receive logs
20602052
* @return FFprobe session created for this execution
20612053
*/
2062-
static async execute(command, completeCallback, logCallback) {
2063-
return FFprobeKit.executeWithArguments(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback);
2054+
static async execute(command) {
2055+
return FFprobeKit.executeWithArguments(FFmpegKitConfig.parseArguments(command));
20642056
}
20652057

20662058
/**
20672059
* <p>Synchronously executes FFprobe with arguments provided.
20682060
*
20692061
* @param commandArguments FFprobe command options/arguments as string array
2070-
* @param completeCallback callback that will be called when the execution has completed
2071-
* @param logCallback callback that will receive logs
20722062
* @return FFprobe session created for this execution
20732063
*/
2074-
static async executeWithArguments(commandArguments, completeCallback, logCallback) {
2075-
let session = await FFprobeSession.create(commandArguments, completeCallback, logCallback);
2064+
static async executeWithArguments(commandArguments) {
2065+
let session = await FFprobeSession.create(commandArguments, undefined, undefined);
20762066

20772067
await FFmpegKitConfig.ffprobeExecute(session);
20782068

@@ -2118,28 +2108,24 @@ export class FFprobeKit {
21182108
* <p>Extracts media information for the file specified with path.
21192109
*
21202110
* @param path path or uri of a media file
2121-
* @param completeCallback callback that will be notified when execution has completed
2122-
* @param logCallback callback that will receive logs
21232111
* @param waitTimeout max time to wait until media information is transmitted
21242112
* @return media information session created for this execution
21252113
*/
2126-
static async getMediaInformation(path, completeCallback, logCallback, waitTimeout) {
2114+
static async getMediaInformation(path, waitTimeout) {
21272115
const commandArguments = ["-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-show_chapters", "-i", path];
2128-
return FFprobeKit.getMediaInformationFromCommandArguments(commandArguments, completeCallback, logCallback, waitTimeout);
2116+
return FFprobeKit.getMediaInformationFromCommandArguments(commandArguments, waitTimeout);
21292117
}
21302118

21312119
/**
21322120
* <p>Extracts media information using the command provided. The command passed to
21332121
* this method must generate the output in JSON format in order to successfully extract media information from it.
21342122
*
21352123
* @param command FFprobe command that prints media information for a file in JSON format
2136-
* @param completeCallback callback that will be notified when execution has completed
2137-
* @param logCallback callback that will receive logs
21382124
* @param waitTimeout max time to wait until media information is transmitted
21392125
* @return media information session created for this execution
21402126
*/
2141-
static async getMediaInformationFromCommand(command, completeCallback, logCallback, waitTimeout) {
2142-
return FFprobeKit.getMediaInformationFromCommandArguments(FFmpegKitConfig.parseArguments(command), completeCallback, logCallback, waitTimeout);
2127+
static async getMediaInformationFromCommand(command, waitTimeout) {
2128+
return FFprobeKit.getMediaInformationFromCommandArguments(FFmpegKitConfig.parseArguments(command), waitTimeout);
21432129
}
21442130

21452131
/**
@@ -2148,16 +2134,19 @@ export class FFprobeKit {
21482134
* from it.
21492135
*
21502136
* @param commandArguments FFprobe command arguments that prints media information for a file in JSON format
2151-
* @param completeCallback callback that will be notified when execution has completed
2152-
* @param logCallback callback that will receive logs
21532137
* @param waitTimeout max time to wait until media information is transmitted
21542138
* @return media information session created for this execution
21552139
*/
2156-
static async getMediaInformationFromCommandArguments(commandArguments, completeCallback, logCallback, waitTimeout) {
2157-
let session = await MediaInformationSession.create(commandArguments, completeCallback, logCallback);
2140+
static async getMediaInformationFromCommandArguments(commandArguments, waitTimeout) {
2141+
let session = await MediaInformationSession.create(commandArguments, undefined, undefined);
21582142

21592143
await FFmpegKitConfig.getMediaInformationExecute(session, waitTimeout);
21602144

2145+
const mediaInformation = await FFmpegKitReactNativeModule.getMediaInformation(session.getSessionId());
2146+
if (mediaInformation !== undefined && mediaInformation !== null) {
2147+
session.setMediaInformation(new MediaInformation(mediaInformation));
2148+
}
2149+
21612150
return session;
21622151
}
21632152

@@ -2214,6 +2203,11 @@ export class FFprobeKit {
22142203

22152204
await FFmpegKitConfig.asyncGetMediaInformationExecute(session, waitTimeout);
22162205

2206+
const mediaInformation = await FFmpegKitReactNativeModule.getMediaInformation(session.getSessionId());
2207+
if (mediaInformation !== undefined && mediaInformation !== null) {
2208+
session.setMediaInformation(new MediaInformation(mediaInformation));
2209+
}
2210+
22172211
return session;
22182212
}
22192213

0 commit comments

Comments
 (0)