Sfoglia il codice sorgente

Use GCD to slightly optimize the performance of screenshots.

cjl_macbook 6 anni fa
parent
commit
691aa871ad
2 ha cambiato i file con 8 aggiunte e 4 eliminazioni
  1. 7 3
      ios/Classes/CoolFlutterIJK.m
  2. 1 1
      ios/Classes/IjkplayerPlugin.m

+ 7 - 3
ios/Classes/CoolFlutterIJK.m

@@ -32,8 +32,9 @@
         textureId = [textures registerTexture:self];
         NSString *channelName = [NSString stringWithFormat:@"top.kikt/ijkplayer/%lli", textureId];
         channel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:[registrar messenger]];
+        __weak typeof(&*self) weakSelf = self;
         [channel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {
-            [self handleMethodCall:call result:result];
+            [weakSelf handleMethodCall:call result:result];
         }];
     }
 
@@ -106,8 +107,11 @@
         controller.playbackVolume = v;
         result(@(YES));
     } else if ([@"screenShot" isEqualToString:call.method]) {
-        NSData *data = [self screenShot];
-        result(data);
+        __weak typeof(&*self) weakSelf = self;
+        dispatch_async(dispatch_get_main_queue(), ^{
+            NSData *data = [weakSelf screenShot];
+            result(data);
+        });
     } else {
         result(FlutterMethodNotImplemented);
     }

+ 1 - 1
ios/Classes/IjkplayerPlugin.m

@@ -53,7 +53,7 @@ static IjkplayerPlugin *__sharedInstance;
 - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
     
     dispatch_queue_t mainQueue = dispatch_get_main_queue();
-    
+//    __weak typeof(&*self) weakSelf = self;
     dispatch_async(mainQueue, ^{
         if ([@"create" isEqualToString:call.method]) {
             @try {