Browse Source

初步完善了iOS的手动全屏逻辑

cjl_macbook 6 years ago
parent
commit
101692c6bc

+ 10 - 4
example/ios/Podfile.lock

@@ -4,13 +4,16 @@ PODS:
     - Flutter
     - FlutterIJK (~> 0.0.8)
   - FlutterIJK (0.0.8)
+  - orientation (0.0.1):
+    - Flutter
   - photo_manager (0.0.1):
     - Flutter
 
 DEPENDENCIES:
   - Flutter (from `.symlinks/flutter/ios`)
-  - flutter_ijkplayer (from `/Users/cai/Documents/GitHub/flutter_ijkplayer/ios/flutter_ijkplayer.podspec`)
-  - photo_manager (from `/Users/cai/.pub-cache/hosted/pub.flutter-io.cn/photo_manager-0.3.3/ios/photo_manager.podspec`)
+  - flutter_ijkplayer (from `/Users/caijinglong/Documents/GitHub/flutter_ijkplayer/ios/flutter_ijkplayer.podspec`)
+  - orientation (from `/Users/caijinglong/.pub-cache/hosted/pub.flutter-io.cn/orientation-1.0.4/ios/orientation.podspec`)
+  - photo_manager (from `/Users/caijinglong/.pub-cache/hosted/pub.flutter-io.cn/photo_manager-0.3.3/ios/photo_manager.podspec`)
 
 SPEC REPOS:
   https://github.com/cocoapods/specs.git:
@@ -20,14 +23,17 @@ EXTERNAL SOURCES:
   Flutter:
     :path: ".symlinks/flutter/ios"
   flutter_ijkplayer:
-    :path: "/Users/cai/Documents/GitHub/flutter_ijkplayer/ios/flutter_ijkplayer.podspec"
+    :path: "/Users/caijinglong/Documents/GitHub/flutter_ijkplayer/ios/flutter_ijkplayer.podspec"
+  orientation:
+    :path: "/Users/caijinglong/.pub-cache/hosted/pub.flutter-io.cn/orientation-1.0.4/ios/orientation.podspec"
   photo_manager:
-    :path: "/Users/cai/.pub-cache/hosted/pub.flutter-io.cn/photo_manager-0.3.3/ios/photo_manager.podspec"
+    :path: "/Users/caijinglong/.pub-cache/hosted/pub.flutter-io.cn/photo_manager-0.3.3/ios/photo_manager.podspec"
 
 SPEC CHECKSUMS:
   Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a
   flutter_ijkplayer: 319c057084d453fd81310129f75f5e6770c6d306
   FlutterIJK: bdcc10a74e25fe5f82ec2331a20ac9cd8c0c7a4b
+  orientation: 46fe7528896a5c3e6215366bcb462c182ebfd4e9
   photo_manager: d47ddf6cb25cbfa837dc334540eb9a99b208e191
 
 PODFILE CHECKSUM: a14c63eb48a9d676ed6d876506b3258fd9c85235

+ 14 - 7
example/lib/page/full_screen.dart

@@ -1,5 +1,4 @@
 import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
 import 'package:flutter_ijkplayer/flutter_ijkplayer.dart';
 
 class FullScreen extends StatefulWidget {
@@ -102,7 +101,8 @@ class _FullScreen2State extends State<FullScreen2> {
   }
 
   Widget buildLandscape() {
-    SystemChrome.setEnabledSystemUIOverlays([]);
+    // SystemChrome.setEnabledSystemUIOverlays([]);
+    // OrientationPlugin.setEnabledSystemUIOverlays([]);
     return WillPopScope(
       child: Scaffold(
         body: Stack(
@@ -114,7 +114,10 @@ class _FullScreen2State extends State<FullScreen2> {
               height: 44.0,
               width: 44.0,
               child: IconButton(
-                icon: Icon(Icons.fullscreen_exit),
+                icon: Icon(
+                  Icons.fullscreen_exit,
+                  color: Colors.white,
+                ),
                 onPressed: portraitUp,
               ),
             ),
@@ -132,10 +135,14 @@ class _FullScreen2State extends State<FullScreen2> {
   }
 
   Widget buildNormal() {
-    SystemChrome.setEnabledSystemUIOverlays([
-      SystemUiOverlay.top,
-      SystemUiOverlay.bottom,
-    ]);
+    // SystemChrome.setEnabledSystemUIOverlays([
+    //   SystemUiOverlay.top,
+    //   SystemUiOverlay.bottom,
+    // ]);
+    // OrientationPlugin.setEnabledSystemUIOverlays([
+    //   SystemUiOverlay.top,
+    //   SystemUiOverlay.bottom,
+    // ]);
     return Scaffold(
       appBar: AppBar(
         title: Text("手动切换全屏(强制)"),

+ 0 - 16
ios/Classes/CoolOrientation.h

@@ -1,16 +0,0 @@
-//
-//  CoolOrientation.h
-//  flutter_ijkplayer
-//
-//  Created by Caijinglong on 2019/3/29.
-//
-
-#import <Foundation/Foundation.h>
-
-NS_ASSUME_NONNULL_BEGIN
-
-@interface CoolOrientation : NSObject
-
-@end
-
-NS_ASSUME_NONNULL_END

+ 0 - 41
ios/Classes/CoolOrientation.m

@@ -1,41 +0,0 @@
-//
-//  CoolOrientation.m
-//  flutter_ijkplayer
-//
-//  Created by Caijinglong on 2019/3/29.
-//
-
-#import "CoolOrientation.h"
-
-const char* const kOrientationUpdateNotificationName = "io.flutter.plugin.platform.SystemChromeOrientationNotificationName";
-const char* const kOrientationUpdateNotificationKey = "io.flutter.plugin.platform.SystemChromeOrientationNotificationKey";
-
-@implementation CoolOrientation
-
-- (void)setSystemChromePreferredOrientations:(NSArray*)orientations {
-    UIInterfaceOrientationMask mask = 0;
-    
-    if (orientations.count == 0) {
-        mask |= UIInterfaceOrientationMaskAll;
-    } else {
-        for (NSString* orientation in orientations) {
-            if ([orientation isEqualToString:@"DeviceOrientation.portraitUp"])
-                mask |= UIInterfaceOrientationMaskPortrait;
-            else if ([orientation isEqualToString:@"DeviceOrientation.portraitDown"])
-                mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
-            else if ([orientation isEqualToString:@"DeviceOrientation.landscapeLeft"])
-                mask |= UIInterfaceOrientationMaskLandscapeLeft;
-            else if ([orientation isEqualToString:@"DeviceOrientation.landscapeRight"])
-                mask |= UIInterfaceOrientationMaskLandscapeRight;
-        }
-    }
-    
-    if (!mask)
-        return;
-    [[NSNotificationCenter defaultCenter] postNotificationName:@(kOrientationUpdateNotificationName)
-                                                        object:nil
-                                                      userInfo:@{@(kOrientationUpdateNotificationKey)
-                                                              :@(mask)}];
-}
-
-@end

+ 27 - 16
ios/Classes/IjkplayerPlugin.m

@@ -3,8 +3,8 @@
 #import "CoolFlutterIjkManager.h"
 #import "CoolFlutterIJK.h"
 
-const char* const kOrientationUpdateNotificationName = "io.flutter.plugin.platform.SystemChromeOrientationNotificationName";
-const char* const kOrientationUpdateNotificationKey = "io.flutter.plugin.platform.SystemChromeOrientationNotificationKey";
+NSString *flutterOrientationNotifyName = @"io.flutter.plugin.platform.SystemChromeOrientationNotificationName";
+const NSString *flutterOrientationNotifyKey = @"io.flutter.plugin.platform.SystemChromeOrientationNotificationKey";
 
 @interface FlutterMethodCall (Ijk)
 - (int64_t)getId;
@@ -32,7 +32,7 @@ static IjkplayerPlugin *__sharedInstance;
         self.registrar = registrar;
         manager = [CoolFlutterIjkManager managerWithRegistrar:registrar];
     }
-
+    
     return self;
 }
 
@@ -144,29 +144,40 @@ static IjkplayerPlugin *__sharedInstance;
         int value = [number intValue];
         UIDeviceOrientation orientation = [self convertIntToOrientation:value];
         NSLog(@"orientation = %ld",orientation);
-        if (value == UIDeviceOrientationPortrait){
+        if (orientation == UIDeviceOrientationPortrait){
             mask |= UIInterfaceOrientationMaskPortrait;
-        }else if (value == UIDeviceOrientationLandscapeLeft) {
+        }else if (orientation == UIDeviceOrientationLandscapeLeft) {
             mask |= UIInterfaceOrientationMaskLandscapeLeft;
-        }else if (value == UIDeviceOrientationPortraitUpsideDown) {
+        }else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
             mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
-        }else if (value == UIDeviceOrientationLandscapeRight) {
+        }else if (orientation == UIDeviceOrientationLandscapeRight) {
             mask |= UIInterfaceOrientationMaskLandscapeRight;
         }
     }
     
-    if (!mask)
-        return;
-    [[NSNotificationCenter defaultCenter] postNotificationName:@(kOrientationUpdateNotificationName)
+    [[NSNotificationCenter defaultCenter] postNotificationName:flutterOrientationNotifyName
                                                         object:nil
-                                                      userInfo:@{@(kOrientationUpdateNotificationKey)
-                                                               :@(mask)}];
+                                                      userInfo:@{flutterOrientationNotifyKey
+                                                                 :@(mask)}];
+    
+    if(orientations.count != 0 && [[UIDevice currentDevice]respondsToSelector:@selector(setOrientation:)]){
+        SEL selector = NSSelectorFromString(@"setOrientation:");
+        int value = [orientations[0] intValue];
+        UIDeviceOrientation orientation = [self convertIntToOrientation:value];
+        int val = orientation;
+        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
+        [invocation setSelector:selector];
+        [invocation setTarget:[UIDevice currentDevice]];
+        [invocation setArgument:&val atIndex:2];
+        [invocation invoke];
+    }
 }
 
 - (void) unlockOrientation {
-    if([[UIDevice currentDevice]respondsToSelector:@selector(setOrientation:)]){
+    UIDevice *device = [UIDevice currentDevice];
+    if([device respondsToSelector:@selector(setOrientation:)]){
         SEL selector = NSSelectorFromString(@"setOrientation:");
-        int val = UIDeviceOrientationUnknown;
+        int val = device.orientation;
         NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
         [invocation setSelector:selector];
         [invocation setTarget:[UIDevice currentDevice]];
@@ -174,9 +185,9 @@ static IjkplayerPlugin *__sharedInstance;
         [invocation invoke];
     }
     
-    [[NSNotificationCenter defaultCenter] postNotificationName:@(kOrientationUpdateNotificationName)
+    [[NSNotificationCenter defaultCenter] postNotificationName:flutterOrientationNotifyName
                                                         object:nil
-                                                      userInfo:@{@(kOrientationUpdateNotificationKey)
+                                                      userInfo:@{flutterOrientationNotifyKey
                                                                  :@(UIInterfaceOrientationMaskAll)}];
 }
 

+ 4 - 4
ios/flutter_ijkplayer.podspec

@@ -18,10 +18,10 @@ A new flutter plugin project.
 
   s.ios.deployment_target = '8.0'
 
-  # s.ios.vendored_frameworks = 'IJKMediaFramework.framework'
-  # s.frameworks  = "AudioToolbox", "AVFoundation", "CoreGraphics", "CoreMedia", "CoreVideo", "MobileCoreServices", "OpenGLES", "QuartzCore", "VideoToolbox", "Foundation", "UIKit", "MediaPlayer"
-  # s.libraries   = "bz2", "z", "stdc++"
-  s.dependency 'FlutterIJK', '~> 0.0.8'
+  s.ios.vendored_frameworks = 'IJKMediaFramework.framework'
+  s.frameworks  = "AudioToolbox", "AVFoundation", "CoreGraphics", "CoreMedia", "CoreVideo", "MobileCoreServices", "OpenGLES", "QuartzCore", "VideoToolbox", "Foundation", "UIKit", "MediaPlayer"
+  s.libraries   = "bz2", "z", "stdc++"
+  # s.dependency 'FlutterIJK', '~> 0.0.8'
 
   # s.script_phase = {:name => 'extract framework', :script=> 'echo "Hello World"; pwd' ,:execution_position => :before_compile}
 

+ 25 - 21
lib/src/engine/manager.dart

@@ -57,17 +57,18 @@ class IjkManager {
     if (Platform.isAndroid) {
       SystemChrome.setPreferredOrientations(list);
     } else if (Platform.isIOS) {
-      var orientations = list.map((v) => v.index).toList();
-      if (list.isEmpty) {
-        _globalChannel.invokeMethod("unlockOrientation");
-      } else {
-        _globalChannel.invokeMethod(
-          "setOrientation",
-          {
-            "orientation": orientations,
-          },
-        );
-      }
+      // var orientations = list.map((v) => v.index).toList();
+      // if (list.isEmpty) {
+      //   _globalChannel.invokeMethod("unlockOrientation");
+      // } else {
+      //   _globalChannel.invokeMethod(
+      //     "setOrientation",
+      //     {
+      //       "orientation": orientations,
+      //     },
+      //   );
+      // }
+      
     }
   }
 
@@ -77,9 +78,8 @@ class IjkManager {
         [DeviceOrientation.landscapeLeft],
       );
     } else if (Platform.isIOS) {
-      _setOrientation(
-        [DeviceOrientation.landscapeLeft],
-      );
+      // OrientationPlugin.forceOrientation(DeviceOrientation.landscapeLeft);
+      _globalChannel.invokeMethod("setOrientation",{"orientation":[DeviceOrientation.landscapeLeft.index]});
     }
   }
 
@@ -88,11 +88,13 @@ class IjkManager {
       await SystemChrome.setPreferredOrientations([
         DeviceOrientation.portraitUp,
       ]);
-      await SystemChrome.restoreSystemUIOverlays();
-    } else {
-      _setOrientation(
-        [DeviceOrientation.portraitUp],
-      );
+      // await SystemChrome.restoreSystemUIOverlays();
+    } else if(Platform.isIOS){
+      // _setOrientation(
+      //   [DeviceOrientation.portraitUp],
+      // );
+      // OrientationPlugin.forceOrientation(null);
+      _globalChannel.invokeMethod("unlockOrientation");
     }
   }
 
@@ -105,8 +107,10 @@ class IjkManager {
       ]);
       await SystemChrome.restoreSystemUIOverlays();
     } else if (Platform.isIOS) {
-      await _setOrientation([]);
-      await SystemChrome.restoreSystemUIOverlays();
+      // await _setOrientation([]);
+      // await SystemChrome.restoreSystemUIOverlays();
+      // OrientationPlugin.setPreferredOrientations([]);
+      _globalChannel.invokeMethod("unlockOrientation");
     }
   }
 }