UIView+VAP.h 5.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // UIView+VAP.h
  2. // Tencent is pleased to support the open source community by making vap available.
  3. //
  4. // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
  5. //
  6. // Licensed under the MIT License (the "License"); you may not use this file except in
  7. // compliance with the License. You may obtain a copy of the License at
  8. //
  9. // http://opensource.org/licenses/MIT
  10. //
  11. // Unless required by applicable law or agreed to in writing, software distributed under the License is
  12. // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  13. // either express or implied. See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #import <UIKit/UIKit.h>
  16. #import "VAPMacros.h"
  17. #import "QGVAPLogger.h"
  18. // 退后台时的行为
  19. typedef NS_ENUM(NSUInteger, HWDMP4EBOperationType) {
  20. HWDMP4EBOperationTypeStop, // 退后台时结束VAP播放
  21. HWDMP4EBOperationTypePauseAndResume, // 退后台时暂停、回到前台时自动恢复 (需要从关键帧解码到当前帧以解决VTSession失效问题,建议低端机型不要设置此选项,暂停时间较长、CPU占用较大)
  22. HWDMP4EBOperationTypeDoNothing, // VAP自身不进行控制,当外部进行控制时可以使用这个,仅用于防止覆盖外界的pause调用的问题
  23. };
  24. @class QGMP4AnimatedImageFrame,QGVAPConfigModel, QGVAPSourceInfo;
  25. /** 注意:回调方法会在子线程被执行。*/
  26. @protocol HWDMP4PlayDelegate <NSObject>
  27. @optional
  28. //即将开始播放时询问,true马上开始播放,false放弃播放
  29. - (BOOL)shouldStartPlayMP4:(VAPView *)container config:(QGVAPConfigModel *)config;
  30. - (void)viewDidStartPlayMP4:(VAPView *)container;
  31. - (void)viewDidPlayMP4AtFrame:(QGMP4AnimatedImageFrame*)frame view:(VAPView *)container;
  32. - (void)viewDidStopPlayMP4:(NSInteger)lastFrameIndex view:(VAPView *)container;
  33. - (void)viewDidFinishPlayMP4:(NSInteger)totalFrameCount view:(VAPView *)container;
  34. - (void)viewDidFailPlayMP4:(NSError *)error;
  35. //vap APIs
  36. - (NSString *)contentForVapTag:(NSString *)tag resource:(QGVAPSourceInfo *)info; //替换配置中的资源占位符(不处理直接返回tag)
  37. - (void)loadVapImageWithURL:(NSString *)urlStr context:(NSDictionary *)context completion:(VAPImageCompletionBlock)completionBlock; //由于组件内不包含网络图片加载的模块,因此需要外部支持图片加载。
  38. @end
  39. @interface UIView (VAP)
  40. @property (nonatomic, weak) id<HWDMP4PlayDelegate> hwd_Delegate;
  41. @property (nonatomic, readonly) QGMP4AnimatedImageFrame *hwd_currentFrame;
  42. @property (nonatomic, strong) NSString *hwd_MP4FilePath;
  43. @property (nonatomic, assign) NSInteger hwd_fps; //fps for dipslay, each frame's duration would be set by fps value before display.
  44. @property (nonatomic, assign) BOOL hwd_renderByOpenGL; //是否使用opengl渲染,默认使用metal
  45. @property (nonatomic, assign) HWDMP4EBOperationType hwd_enterBackgroundOP; // 在退后台时的行为,默认为结束
  46. - (void)playHWDMp4:(NSString *)filePath;
  47. - (void)playHWDMP4:(NSString *)filePath delegate:(id<HWDMP4PlayDelegate>)delegate;
  48. - (void)playHWDMP4:(NSString *)filePath repeatCount:(NSInteger)repeatCount delegate:(id<HWDMP4PlayDelegate>)delegate;
  49. - (void)stopHWDMP4;
  50. - (void)pauseHWDMP4;
  51. - (void)resumeHWDMP4;
  52. + (void)registerHWDLog:(QGVAPLoggerFunc)logger;
  53. @end
  54. @interface UIView (VAPGesture)
  55. //增加点击的手势识别
  56. - (void)addVapTapGesture:(VAPGestureEventBlock)handler;
  57. //手势识别通用接口
  58. - (void)addVapGesture:(UIGestureRecognizer *)gestureRecognizer callback:(VAPGestureEventBlock)handler;
  59. @end
  60. @interface UIView (VAPMask)
  61. @property (nonatomic, strong) QGVAPMaskInfo *vap_maskInfo;
  62. @end
  63. @interface UIView (MP4HWDDeprecated)
  64. - (void)playHWDMP4:(NSString *)filePath blendMode:(QGHWDTextureBlendMode)mode delegate:(id<HWDMP4PlayDelegate>)delegate __attribute__((deprecated("QGHWDTextureBlendMode is no longer work in vap, use playHWDMP4:delegate: instead")));
  65. - (void)playHWDMP4:(NSString *)filePath blendMode:(QGHWDTextureBlendMode)mode repeatCount:(NSInteger)repeatCount delegate:(id<HWDMP4PlayDelegate>)delegate __attribute__((deprecated("QGHWDTextureBlendMode is no longer work in vap, use playHWDMP4:repeatCount:delegate: instead")));
  66. - (void)playHWDMP4:(NSString *)filePath fps:(NSInteger)fps delegate:(id<HWDMP4PlayDelegate>)delegate __attribute__((deprecated("customized fps is not recommended, use playHWDMP4:delegate: instead")));
  67. - (void)playHWDMP4:(NSString *)filePath fps:(NSInteger)fps repeatCount:(NSInteger)repeatCount delegate:(id<HWDMP4PlayDelegate>)delegate __attribute__((deprecated("customized fps is not recommended, use playHWDMP4:repeatCount:delegate: instead")));
  68. - (void)playHWDMP4:(NSString *)filePath fps:(NSInteger)fps blendMode:(QGHWDTextureBlendMode)mode delegate:(id<HWDMP4PlayDelegate>)delegate __attribute__((deprecated("customized fps is not recommended, use playHWDMP4:delegate: instead")));
  69. - (void)playHWDMP4:(NSString *)filePath fps:(NSInteger)fps blendMode:(QGHWDTextureBlendMode)mode repeatCount:(NSInteger)repeatCount delegate:(id<HWDMP4PlayDelegate>)delegate __attribute__((deprecated("customized fps is not recommended, use playHWDMP4:repeatCount:delegate: instead")));
  70. @end