Browse Source

feat: WrapView在播放完后自动移除,防止用法不正确时停留在显示素材最后一帧

yuxiangshen 5 năm trước cách đây
mục cha
commit
d4dfe0d96f

+ 1 - 1
QGVAPlayer.podspec

@@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
   #
 
   spec.name         = "QGVAPlayer"
-  spec.version      = "1.0.6"
+  spec.version      = "1.0.7"
   spec.summary      = "video animation player."
   spec.platform     = :ios, "8.0"
 

+ 68 - 0
iOS/.gitignore

@@ -0,0 +1,68 @@
+# Xcode
+#
+# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
+
+## User settings
+xcuserdata/
+
+## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
+*.xcscmblueprint
+*.xccheckout
+
+## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
+build/
+DerivedData/
+*.moved-aside
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+
+## Obj-C/Swift specific
+*.hmap
+
+## App packaging
+*.ipa
+*.dSYM.zip
+*.dSYM
+
+# CocoaPods
+#
+# We recommend against adding the Pods directory to your .gitignore. However
+# you should judge for yourself, the pros and cons are mentioned at:
+# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
+#
+# Pods/
+#
+# Add this line if you want to avoid checking in source code from the Xcode workspace
+# *.xcworkspace
+
+# Carthage
+#
+# Add this line if you want to avoid checking in source code from Carthage dependencies.
+# Carthage/Checkouts
+
+Carthage/Build/
+
+# fastlane
+#
+# It is recommended to not store the screenshots in the git repo.
+# Instead, use fastlane to re-generate the screenshots whenever they are needed.
+# For more information about the recommended setup visit:
+# https://docs.fastlane.tools/best-practices/source-control/#source-control
+
+fastlane/report.xml
+fastlane/Preview.html
+fastlane/screenshots/**/*.png
+fastlane/test_output
+
+# Code Injection
+#
+# After new code Injection tools there's a generated folder /iOSInjectionProject
+# https://github.com/johnno1962/injectionforxcode
+
+iOSInjectionProject/

+ 2 - 0
iOS/QGVAPlayer/QGVAPlayer/Classes/QGVAPWrapView.h

@@ -47,6 +47,8 @@ typedef NS_ENUM(NSUInteger, QGVAPWrapViewContentMode) {
 @interface QGVAPWrapView : UIView
 /// default is QGVAPWrapViewContentModeScaleToFill
 @property (nonatomic, assign) QGVAPWrapViewContentMode contentMode;
+// 是否在播放完成后自动移除内部VAPView, 如果外部用法会复用当前View,可以不移除
+@property (nonatomic, assign) BOOL autoDestoryAfterFinish;
 
 - (void)vapWrapView_playHWDMP4:(NSString *)filePath
                    repeatCount:(NSInteger)repeatCount

+ 17 - 2
iOS/QGVAPlayer/QGVAPlayer/Classes/QGVAPWrapView.m

@@ -41,8 +41,15 @@
 }
 
 - (void)commonInit {
-    self.vapView = [[VAPView alloc] initWithFrame:self.bounds];
-    [self addSubview:self.vapView];
+    _autoDestoryAfterFinish = YES;
+}
+
+// 因为播放停止后可能移除VAPView,这里需要加回来
+- (void)initVAPViewIfNeed {
+    if (!_vapView) {
+        _vapView = [[VAPView alloc] initWithFrame:self.bounds];
+        [self addSubview:_vapView];
+    }
 }
 
 - (void)vapWrapView_playHWDMP4:(NSString *)filePath
@@ -51,6 +58,7 @@
     
     self.delegate = delegate;
     
+    [self initVAPViewIfNeed];
     [self.vapView playHWDMP4:filePath repeatCount:repeatCount delegate:self];
 }
 
@@ -130,6 +138,13 @@
     if ([self.delegate respondsToSelector:@selector(vapWrap_viewDidStopPlayMP4:view:)]) {
         [self.delegate vapWrap_viewDidStopPlayMP4:lastFrameIndex view:container];
     }
+    
+    dispatch_async(dispatch_get_main_queue(), ^{
+        if (self.autoDestoryAfterFinish) {
+            [self.vapView removeFromSuperview];
+            self.vapView = nil;
+        }
+    });
 }
 
 - (BOOL)shouldStartPlayMP4:(VAPView *)container config:(QGVAPConfigModel *)config {

+ 2 - 1
iOS/QGVAPlayerDemo/QGVAPlayerDemo/ViewController.m

@@ -109,6 +109,7 @@ void qg_VAP_Logger_handler(VAPLogLevel level, const char* file, int line, const
     QGVAPWrapView *wrapView = [[QGVAPWrapView alloc] initWithFrame:self.view.bounds];
     wrapView.center = self.view.center;
     wrapView.contentMode = QGVAPWrapViewContentModeAspectFit;
+    wrapView.autoDestoryAfterFinish = YES;
     [self.view addSubview:wrapView];
     NSString *resPath = [NSString stringWithFormat:@"%@/Resource/demo.mp4", [[NSBundle mainBundle] resourcePath]];
     [wrapView vapWrapView_playHWDMP4:resPath repeatCount:-1 delegate:self];
@@ -134,7 +135,7 @@ void qg_VAP_Logger_handler(VAPLogLevel level, const char* file, int line, const
 - (void)viewDidStopPlayMP4:(NSInteger)lastFrameIndex view:(UIView *)container {
     //note:在子线程被调用
     dispatch_async(dispatch_get_main_queue(), ^{
-        //do something
+        [container removeFromSuperview];
     });
 }