1010#import < Photos/Photos.h>
1111#import " VIMediaCache.h"
1212
13+ // TODO(recastrodiaz) remove duplicate interface. Taken from messages.m
14+ @interface FLTTextureMessage ()
15+ + (FLTTextureMessage*)fromMap : (NSDictionary *)dict ;
16+ - (NSDictionary *)toMap ;
17+ @end
18+
1319@interface VIMediaCacheSingleton : NSObject {
1420 VIResourceLoaderManager* resourceLoaderManager;
1521}
@@ -848,7 +854,9 @@ - (void)initialize:(FlutterError* __autoreleasing*)error {
848854 [_players removeAllObjects ];
849855}
850856
851- - (FLTTextureMessage*)create : (FLTCreateMessage*)input error : (FlutterError**)error {
857+ - (FLTTextureMessage*)create : (FLTCreateMessage*)input
858+ error : (FlutterError* __strong*)error
859+ callback : (FlutterReply)callback {
852860 FLTFrameUpdater* frameUpdater = [[FLTFrameUpdater alloc ] initWithRegistry: _registry];
853861 FLTVideoPlayer* player;
854862 if (input.asset ) {
@@ -859,7 +867,9 @@ - (FLTTextureMessage*)create:(FLTCreateMessage*)input error:(FlutterError**)erro
859867 assetPath = [_registrar lookupKeyForAsset: input.asset];
860868 }
861869 player = [[FLTVideoPlayer alloc ] initWithAsset: assetPath frameUpdater: frameUpdater];
862- return [self onPlayerSetup: player frameUpdater: frameUpdater];
870+ FLTTextureMessage* output = [self onPlayerSetup: player frameUpdater: frameUpdater];
871+ callback (wrapResult ([output toMap ], *error));
872+ return nil ;
863873 } else if (input.uri ) {
864874 NSString * phAssetPrefix = @" phasset://" ;
865875 if ([input.uri hasPrefix: phAssetPrefix]) {
@@ -869,16 +879,22 @@ - (FLTTextureMessage*)create:(FLTCreateMessage*)input error:(FlutterError**)erro
869879 initWithPHAssetLocalIdentifier: phAssetArg
870880 frameUpdater: frameUpdater
871881 onPlayerCreated: ^(FLTVideoPlayer* player) {
872- [self onPlayerSetup: player frameUpdater: frameUpdater];
882+ FLTTextureMessage* output =
883+ [self onPlayerSetup: player frameUpdater: frameUpdater];
884+ callback (wrapResult ([output toMap ], *error));
873885 }];
874886 return nil ;
875887 } else {
876888 player = [[FLTVideoPlayer alloc ] initWithURL: [NSURL URLWithString: input.uri]
877889 frameUpdater: frameUpdater];
878- return [self onPlayerSetup: player frameUpdater: frameUpdater];
890+ FLTTextureMessage* output = [self onPlayerSetup: player frameUpdater: frameUpdater];
891+ callback (wrapResult ([output toMap ], *error));
892+ return nil ;
879893 }
880894 } else {
881895 *error = [FlutterError errorWithCode: @" video_player" message: @" not implemented" details: nil ];
896+ FLTTextureMessage* output = nil ;
897+ callback (wrapResult ([output toMap ], *error));
882898 return nil ;
883899 }
884900}
@@ -950,4 +966,18 @@ - (void)pause:(FLTTextureMessage*)input error:(FlutterError**)error {
950966 [player pause ];
951967}
952968
969+ // TODO(recastrodiaz) remove duplicate function. Taken from messages.m
970+ static NSDictionary * wrapResult (NSDictionary * result, FlutterError* error) {
971+ NSDictionary * errorDict = (NSDictionary *)[NSNull null ];
972+ if (error) {
973+ errorDict = [NSDictionary
974+ dictionaryWithObjectsAndKeys: (error.code ? error.code : [NSNull null ]), @" code" ,
975+ (error.message ? error.message : [NSNull null ]), @" message" ,
976+ (error.details ? error.details : [NSNull null ]), @" details" ,
977+ nil ];
978+ }
979+ return [NSDictionary dictionaryWithObjectsAndKeys: (result ? result : [NSNull null ]), @" result" ,
980+ errorDict, @" error" , nil ];
981+ }
982+
953983@end
0 commit comments