SLAvPlayer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // SLAvPlayer.h
  3. // DarkMode
  4. //
  5. // Created by wsl on 2019/9/20.
  6. // Copyright © 2019 wsl. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <UIKit/UIKit.h>
  10. #import <AVKit/AVKit.h>
  11. NS_ASSUME_NONNULL_BEGIN
  12. @class SLAvPlayer;
  13. @protocol SLAvPlayerDelegate <NSObject>
  14. @optional
  15. /// 播放中
  16. /// @param avPlayer 播放器
  17. /// @param currentTime 当前时间
  18. /// @param totalTime 总时间
  19. - (void)avPlayer:(SLAvPlayer *)avPlayer playingToCurrentTime:(CMTime)currentTime totalTime:(CMTime)totalTime;
  20. /// 播放结束 暂停
  21. - (void)playDidEndOnAvplyer:(SLAvPlayer *)avPlayer;
  22. @end
  23. /// 简易播放器
  24. @interface SLAvPlayer : NSObject
  25. /// 播放源
  26. @property (nonatomic, strong) NSURL *url;
  27. /// 视频尺寸 单位像素 px
  28. @property (nonatomic, assign, readonly) CGSize naturalSize;
  29. /// 总时长
  30. @property (nonatomic, assign, readonly) CMTime duration;
  31. /// 视频展示区域 显示器
  32. @property (nonatomic, strong, nullable) UIView *monitor;
  33. /// 代理
  34. @property (nonatomic, weak) id <SLAvPlayerDelegate> delegate;
  35. + (instancetype)sharedAVPlayer;
  36. ///开始播放
  37. - (void)play;
  38. ///暂停
  39. - (void)pause;
  40. ///结束播放 销毁播放器
  41. - (void)stop;
  42. ///跳转到time节点并暂停
  43. - (void)seekToTime:(CMTime)time completionHandler:(void (^_Nullable)(BOOL finished))completionHandler;
  44. @end
  45. NS_ASSUME_NONNULL_END