123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489 |
- //
- // ZFPlayerController.h
- // ZFPlayer
- //
- // Copyright (c) 2016年 任子丰 ( http://github.com/renzifeng )
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- #import <Foundation/Foundation.h>
- #import <UIKit/UIKit.h>
- #import "ZFPlayerMediaPlayback.h"
- #import "ZFOrientationObserver.h"
- #import "ZFPlayerMediaControl.h"
- #import "ZFPlayerGestureControl.h"
- #import "ZFPlayerNotification.h"
- #import "ZFFloatView.h"
- #import "UIScrollView+ZFPlayer.h"
- NS_ASSUME_NONNULL_BEGIN
- @interface ZFPlayerController : NSObject
- /// The video contrainerView in normal model.
- @property (nonatomic, strong) UIView *containerView;
- /// The currentPlayerManager must conform `ZFPlayerMediaPlayback` protocol.
- @property (nonatomic, strong) id<ZFPlayerMediaPlayback> currentPlayerManager;
- /// The custom controlView must conform `ZFPlayerMediaControl` protocol.
- @property (nonatomic, strong) UIView<ZFPlayerMediaControl> *controlView;
- /// The notification manager class.
- @property (nonatomic, strong, readonly) ZFPlayerNotification *notification;
- /// The container view type.
- @property (nonatomic, assign, readonly) ZFPlayerContainerType containerType;
- /// The player's small container view.
- @property (nonatomic, strong, readonly) ZFFloatView *smallFloatView;
- /// Whether the small window is displayed.
- @property (nonatomic, assign, readonly) BOOL isSmallFloatViewShow;
- /*!
- @method playerWithPlayerManager:containerView:
- @abstract Create an ZFPlayerController that plays a single audiovisual item.
- @param playerManager must conform `ZFPlayerMediaPlayback` protocol.
- @param containerView to see the video frames must set the contrainerView.
- @result An instance of ZFPlayerController.
- */
- + (instancetype)playerWithPlayerManager:(id<ZFPlayerMediaPlayback>)playerManager containerView:(UIView *)containerView;
- /*!
- @method initWithPlayerManager:containerView:
- @abstract Create an ZFPlayerController that plays a single audiovisual item.
- @param playerManager must conform `ZFPlayerMediaPlayback` protocol.
- @param containerView to see the video frames must set the contrainerView.
- @result An instance of ZFPlayerController.
- */
- - (instancetype)initWithPlayerManager:(id<ZFPlayerMediaPlayback>)playerManager containerView:(UIView *)containerView;
- /*!
- @method playerWithScrollView:playerManager:containerViewTag:
- @abstract Create an ZFPlayerController that plays a single audiovisual item. Use in `UITableView` or `UICollectionView`.
- @param scrollView is `tableView` or `collectionView`.
- @param playerManager must conform `ZFPlayerMediaPlayback` protocol.
- @param containerViewTag to see the video at scrollView must set the contrainerViewTag.
- @result An instance of ZFPlayerController.
- */
- + (instancetype)playerWithScrollView:(UIScrollView *)scrollView playerManager:(id<ZFPlayerMediaPlayback>)playerManager containerViewTag:(NSInteger)containerViewTag;
- /*!
- @method initWithScrollView:playerManager:containerViewTag:
- @abstract Create an ZFPlayerController that plays a single audiovisual item. Use in `UITableView` or `UICollectionView`.
- @param scrollView is `tableView` or `collectionView`.
- @param playerManager must conform `ZFPlayerMediaPlayback` protocol.
- @param containerViewTag to see the video at scrollView must set the contrainerViewTag.
- @result An instance of ZFPlayerController.
- */
- - (instancetype)initWithScrollView:(UIScrollView *)scrollView playerManager:(id<ZFPlayerMediaPlayback>)playerManager containerViewTag:(NSInteger)containerViewTag;
- /*!
- @method playerWithScrollView:playerManager:containerView:
- @abstract Create an ZFPlayerController that plays a single audiovisual item. Use in `UIScrollView`.
- @param playerManager must conform `ZFPlayerMediaPlayback` protocol.
- @param containerView to see the video at the scrollView.
- @result An instance of ZFPlayerController.
- */
- + (instancetype)playerWithScrollView:(UIScrollView *)scrollView playerManager:(id<ZFPlayerMediaPlayback>)playerManager containerView:(UIView *)containerView;
- /*!
- @method initWithScrollView:playerManager:containerView:
- @abstract Create an ZFPlayerController that plays a single audiovisual item. Use in `UIScrollView`.
- @param playerManager must conform `ZFPlayerMediaPlayback` protocol.
- @param containerView to see the video at the scrollView.
- @result An instance of ZFPlayerController.
- */
- - (instancetype)initWithScrollView:(UIScrollView *)scrollView playerManager:(id<ZFPlayerMediaPlayback>)playerManager containerView:(UIView *)containerView;
- @end
- @interface ZFPlayerController (ZFPlayerTimeControl)
- /// The player current play time.
- @property (nonatomic, readonly) NSTimeInterval currentTime;
- /// The player total time.
- @property (nonatomic, readonly) NSTimeInterval totalTime;
- /// The player buffer time.
- @property (nonatomic, readonly) NSTimeInterval bufferTime;
- /// The player progress, 0...1
- @property (nonatomic, readonly) float progress;
- /// The player bufferProgress, 0...1
- @property (nonatomic, readonly) float bufferProgress;
- /**
- Use this method to seek to a specified time for the current player and to be notified when the seek operation is complete.
- @param time seek time.
- @param completionHandler completion handler.
- */
- - (void)seekToTime:(NSTimeInterval)time completionHandler:(void (^ __nullable)(BOOL finished))completionHandler;
- @end
- @interface ZFPlayerController (ZFPlayerPlaybackControl)
- /// 0...1.0
- /// Only affects audio volume for the device instance and not for the player.
- /// You can change device volume or player volume as needed,change the player volume you can conform the `ZFPlayerMediaPlayback` protocol.
- @property (nonatomic) float volume;
- /// The device muted.
- /// Only affects audio muting for the device instance and not for the player.
- /// You can change device mute or player mute as needed,change the player mute you can conform the `ZFPlayerMediaPlayback` protocol.
- @property (nonatomic, getter=isMuted) BOOL muted;
- // 0...1.0, where 1.0 is maximum brightness. Only supported by main screen.
- @property (nonatomic) float brightness;
- /// The play asset URL.
- @property (nonatomic) NSURL *assetURL;
- /// If tableView or collectionView has only one section , use `assetURLs`.
- /// If tableView or collectionView has more sections , use `sectionAssetURLs`.
- /// Set this you can use `playTheNext` `playThePrevious` `playTheIndex:` method.
- @property (nonatomic, copy, nullable) NSArray <NSURL *>*assetURLs;
- /// The currently playing index,limited to one-dimensional arrays.
- @property (nonatomic) NSInteger currentPlayIndex;
- /// is the last asset URL in `assetURLs`.
- @property (nonatomic, readonly) BOOL isLastAssetURL;
- /// is the first asset URL in `assetURLs`.
- @property (nonatomic, readonly) BOOL isFirstAssetURL;
- /// If Yes, player will be called pause method When Received `UIApplicationWillResignActiveNotification` notification.
- /// default is YES.
- @property (nonatomic) BOOL pauseWhenAppResignActive;
- /// When the player is playing, it is paused by some event,not by user click to pause.
- /// For example, when the player is playing, application goes into the background or pushed to another viewController
- @property (nonatomic, getter=isPauseByEvent) BOOL pauseByEvent;
- /// The current player controller is disappear, not dealloc
- @property (nonatomic, getter=isViewControllerDisappear) BOOL viewControllerDisappear;
- /// You can custom the AVAudioSession,
- /// default is NO.
- @property (nonatomic, assign) BOOL customAudioSession;
- /// The block invoked when the player is Prepare to play.
- @property (nonatomic, copy, nullable) void(^playerPrepareToPlay)(id<ZFPlayerMediaPlayback> asset, NSURL *assetURL);
- /// The block invoked when the player is Ready to play.
- @property (nonatomic, copy, nullable) void(^playerReadyToPlay)(id<ZFPlayerMediaPlayback> asset, NSURL *assetURL);
- /// The block invoked when the player play progress changed.
- @property (nonatomic, copy, nullable) void(^playerPlayTimeChanged)(id<ZFPlayerMediaPlayback> asset, NSTimeInterval currentTime, NSTimeInterval duration);
- /// The block invoked when the player play buffer changed.
- @property (nonatomic, copy, nullable) void(^playerBufferTimeChanged)(id<ZFPlayerMediaPlayback> asset, NSTimeInterval bufferTime);
- /// The block invoked when the player playback state changed.
- @property (nonatomic, copy, nullable) void(^playerPlayStateChanged)(id<ZFPlayerMediaPlayback> asset, ZFPlayerPlaybackState playState);
- /// The block invoked when the player load state changed.
- @property (nonatomic, copy, nullable) void(^playerLoadStateChanged)(id<ZFPlayerMediaPlayback> asset, ZFPlayerLoadState loadState);
- /// The block invoked when the player play failed.
- @property (nonatomic, copy, nullable) void(^playerPlayFailed)(id<ZFPlayerMediaPlayback> asset, id error);
- /// The block invoked when the player play end.
- @property (nonatomic, copy, nullable) void(^playerDidToEnd)(id<ZFPlayerMediaPlayback> asset);
- // The block invoked when video size changed.
- @property (nonatomic, copy, nullable) void(^presentationSizeChanged)(id<ZFPlayerMediaPlayback> asset, CGSize size);
- /**
- Play the next url ,while the `assetURLs` is not NULL.
- */
- - (void)playTheNext;
- /**
- Play the previous url ,while the `assetURLs` is not NULL.
- */
- - (void)playThePrevious;
- /**
- Play the index of url ,while the `assetURLs` is not NULL.
- @param index play the index.
- */
- - (void)playTheIndex:(NSInteger)index;
- /**
- Player stop and playerView remove from super view,remove other notification.
- */
- - (void)stop;
- /*!
- @method replaceCurrentPlayerManager:
- @abstract Replaces the player's current playeranager with the specified player item.
- @param manager must conform `ZFPlayerMediaPlayback` protocol
- @discussion The playerManager that will become the player's current playeranager.
- */
- - (void)replaceCurrentPlayerManager:(id<ZFPlayerMediaPlayback>)manager;
- /**
- Add video to the cell.
- */
- - (void)addPlayerViewToCell;
- /**
- Add video to the container view.
- */
- - (void)addPlayerViewToContainerView:(UIView *)containerView;
- /**
- Add to the keyWindow.
- */
- - (void)addPlayerViewToKeyWindow;
- /**
- Stop the current playing video and remove the playerView.
- */
- - (void)stopCurrentPlayingView;
- /**
- stop the current playing video on cell.
- */
- - (void)stopCurrentPlayingCell;
- @end
- @interface ZFPlayerController (ZFPlayerOrientationRotation)
- @property (nonatomic, readonly) ZFOrientationObserver *orientationObserver;
- /// Whether automatic screen rotation is supported.
- /// iOS8.1~iOS8.3 the value is YES, other iOS version the value is NO.
- /// This property is used for the return value of UIViewController `shouldAutorotate` method.
- @property (nonatomic, readonly) BOOL shouldAutorotate;
- /// Whether allow the video orientation rotate.
- /// default is YES.
- @property (nonatomic) BOOL allowOrentitaionRotation;
- /// When ZFFullScreenMode is ZFFullScreenModeLandscape the orientation is LandscapeLeft or LandscapeRight, this value is YES.
- /// When ZFFullScreenMode is ZFFullScreenModePortrait, while the player fullSceen this value is YES.
- @property (nonatomic, readonly) BOOL isFullScreen;
- /// when call the `stop` method, exit the fullScreen model, default is YES.
- @property (nonatomic, assign) BOOL exitFullScreenWhenStop;
- /// Lock the screen orientation.
- @property (nonatomic, getter=isLockedScreen) BOOL lockedScreen;
- /// The statusbar hidden.
- @property (nonatomic, getter=isStatusBarHidden) BOOL statusBarHidden;
- /// Use device orientation, default NO.
- @property (nonatomic, assign) BOOL forceDeviceOrientation;
- /// The current orientation of the player.
- /// Default is UIInterfaceOrientationPortrait.
- @property (nonatomic, readonly) UIInterfaceOrientation currentOrientation;
- /// The block invoked When player will rotate.
- @property (nonatomic, copy, nullable) void(^orientationWillChange)(ZFPlayerController *player, BOOL isFullScreen);
- /// The block invoked when player rotated.
- @property (nonatomic, copy, nullable) void(^orientationDidChanged)(ZFPlayerController *player, BOOL isFullScreen);
- /**
- Add the device orientation observer.
- */
- - (void)addDeviceOrientationObserver;
- /**
- Remove the device orientation observer.
- */
- - (void)removeDeviceOrientationObserver;
- /**
- Enter the fullScreen while the ZFFullScreenMode is ZFFullScreenModeLandscape.
- @param orientation UIInterfaceOrientation
- @param animated is animated.
- */
- - (void)enterLandscapeFullScreen:(UIInterfaceOrientation)orientation animated:(BOOL)animated;
- /**
- Enter the fullScreen while the ZFFullScreenMode is ZFFullScreenModePortrait.
- @param fullScreen is fullscreen.
- @param animated is animated.
- */
- - (void)enterPortraitFullScreen:(BOOL)fullScreen animated:(BOOL)animated;
- /**
- FullScreen mode is determined by ZFFullScreenMode.
- @param fullScreen is fullscreen.
- @param animated is animated.
- */
- - (void)enterFullScreen:(BOOL)fullScreen animated:(BOOL)animated;
- @end
- @interface ZFPlayerController (ZFPlayerViewGesture)
- /// An instance of ZFPlayerGestureControl.
- @property (nonatomic, readonly) ZFPlayerGestureControl *gestureControl;
- /// The gesture types that the player not support.
- @property (nonatomic, assign) ZFPlayerDisableGestureTypes disableGestureTypes;
- /// The pan gesture moving direction that the player not support.
- @property (nonatomic) ZFPlayerDisablePanMovingDirection disablePanMovingDirection;
- @end
- @interface ZFPlayerController (ZFPlayerScrollView)
- /// The scroll view is `tableView` or `collectionView`.
- @property (nonatomic, readonly, nullable) UIScrollView *scrollView;
- /// The scrollView player should auto player, default is YES.
- @property (nonatomic) BOOL shouldAutoPlay;
- /// WWAN network auto play, only support in scrollView mode when the `shouldAutoPlay` is YES, default is NO.
- @property (nonatomic, getter=isWWANAutoPlay) BOOL WWANAutoPlay;
- /// The indexPath is playing.
- @property (nonatomic, readonly, nullable) NSIndexPath *playingIndexPath;
- /// The indexPath should be play while scrolling.
- @property (nonatomic, readonly, nullable) NSIndexPath *shouldPlayIndexPath;
- /// The view tag that the player display in scrollView.
- @property (nonatomic, readonly) NSInteger containerViewTag;
- /// The current playing cell stop playing when the cell has out off the screen,defalut is YES.
- @property (nonatomic) BOOL stopWhileNotVisible;
- /**
- The current player scroll slides off the screen percent.
- the property used when the `stopWhileNotVisible` is YES, stop the current playing player.
- the property used when the `stopWhileNotVisible` is NO, the current playing player add to small container view.
- The range is 0.0~1.0, defalut is 0.5.
- 0.0 is the player will disappear.
- 1.0 is the player did disappear.
- */
- @property (nonatomic) CGFloat playerDisapperaPercent;
- /**
- The current player scroll to the screen percent to play the video.
- The range is 0.0~1.0, defalut is 0.0.
- 0.0 is the player will appear.
- 1.0 is the player did appear.
- */
- @property (nonatomic) CGFloat playerApperaPercent;
- /// If tableView or collectionView has more sections, use `sectionAssetURLs`.
- @property (nonatomic, copy, nullable) NSArray <NSArray <NSURL *>*>*sectionAssetURLs;
- /// The block invoked When the player appearing.
- @property (nonatomic, copy, nullable) void(^zf_playerAppearingInScrollView)(NSIndexPath *indexPath, CGFloat playerApperaPercent);
- /// The block invoked When the player disappearing.
- @property (nonatomic, copy, nullable) void(^zf_playerDisappearingInScrollView)(NSIndexPath *indexPath, CGFloat playerDisapperaPercent);
- /// The block invoked When the player will appeared.
- @property (nonatomic, copy, nullable) void(^zf_playerWillAppearInScrollView)(NSIndexPath *indexPath);
- /// The block invoked When the player did appeared.
- @property (nonatomic, copy, nullable) void(^zf_playerDidAppearInScrollView)(NSIndexPath *indexPath);
- /// The block invoked When the player will disappear.
- @property (nonatomic, copy, nullable) void(^zf_playerWillDisappearInScrollView)(NSIndexPath *indexPath);
- /// The block invoked When the player did disappeared.
- @property (nonatomic, copy, nullable) void(^zf_playerDidDisappearInScrollView)(NSIndexPath *indexPath);
- /// The block invoked When the player should play.
- @property (nonatomic, copy, nullable) void(^zf_playerShouldPlayInScrollView)(NSIndexPath *indexPath);
- /// The block invoked When the player did stop scroll.
- @property (nonatomic, copy, nullable) void(^zf_scrollViewDidEndScrollingCallback)(NSIndexPath *indexPath);
- /// Filter the cell that should be played when the scroll is stopped (to play when the scroll is stopped).
- - (void)zf_filterShouldPlayCellWhileScrolled:(void (^ __nullable)(NSIndexPath *indexPath))handler;
- /// Filter the cell that should be played while scrolling (you can use this to filter the highlighted cell).
- - (void)zf_filterShouldPlayCellWhileScrolling:(void (^ __nullable)(NSIndexPath *indexPath))handler;
- /**
- Play the indexPath of url, while the `assetURLs` or `sectionAssetURLs` is not NULL.
- @param indexPath Play the indexPath of url.
- */
- - (void)playTheIndexPath:(NSIndexPath *)indexPath;
- /**
- Play the indexPath of url ,while the `assetURLs` or `sectionAssetURLs` is not NULL.
-
- @param indexPath Play the indexPath of url
- @param scrollToTop Scroll the current cell to top with animations.
- */
- - (void)playTheIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop;
- /**
- Play the indexPath of url ,while the `assetURLs` or `sectionAssetURLs` is not NULL.
-
- @param indexPath Play the indexPath of url
- @param assetURL The player URL.
- @param scrollToTop Scroll the current cell to top with animations.
- */
- - (void)playTheIndexPath:(NSIndexPath *)indexPath assetURL:(NSURL *)assetURL scrollToTop:(BOOL)scrollToTop;
- /**
- Play the indexPath of url ,while the `assetURLs` or `sectionAssetURLs` is not NULL.
-
- @param indexPath Play the indexPath of url
- @param scrollToTop scroll the current cell to top with animations.
- @param completionHandler Scroll completion callback.
- */
- - (void)playTheIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop completionHandler:(void (^ __nullable)(void))completionHandler;
- @end
- @interface ZFPlayerController (ZFPlayerDeprecated)
- /**
- Add the playerView to cell.
- */
- - (void)updateScrollViewPlayerToCell __attribute__((deprecated("use `addPlayerViewToCell:` instead.")));
- /**
- Add the playerView to containerView.
-
- @param containerView The playerView containerView.
- */
- - (void)updateNoramlPlayerWithContainerView:(UIView *)containerView __attribute__((deprecated("use `addPlayerViewToContainerView:` instead.")));
- @end
- NS_ASSUME_NONNULL_END
|