单军华
2018-07-12 3e8437ae559487362fae3525beb79c534c213a51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
//
//  ZFPlayer.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 "ZFFloatView.h"
 
NS_ASSUME_NONNULL_BEGIN
 
@interface ZFPlayerController : NSObject
 
/// The video contrainerView in normal model.
@property (nonatomic, readonly) UIView *containerView;
 
/// The currentPlayerManager must conform `ZFPlayerMediaPlayback` protocol.
@property (nonatomic, readonly) id<ZFPlayerMediaPlayback> currentPlayerManager;
 
/// The custom controlView must conform `ZFPlayerMediaControl` protocol.
@property (nonatomic, strong) UIView<ZFPlayerMediaControl> *controlView;
 
/*!
 @method            playerWithPlayerManager:
 @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            playerWithPlayerManager:
 @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:
 @abstract          Create an ZFPlayerController that plays a single audiovisual item. Use in `tableView` or `collectionView`.
 @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            playerWithScrollView:playerManager:
 @abstract          Create an ZFPlayerController that plays a single audiovisual item. Use in `tableView` or `collectionView`.
 @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;
 
@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.
- (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 folllow the `ZFPlayerMediaPlayback` protocol.
@property (nonatomic) float volume;
 
/// 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 folllow 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;
 
/// WWAN network auto play, default is NO.
@property (nonatomic, getter=isWWANAutoPlay) BOOL WWANAutoPlay;
 
/// The play asset URL.
@property (nonatomic) NSURL *assetURL;
 
/// if tableView or collectionView has only one section , use sectionAssetURLs.
/// if normal model set this can use `playTheNext` `playThePrevious` `playTheIndex:`.
@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 play end.
@property (nonatomic, copy, nullable) void(^playerDidToEnd)(id asset);
 
 
/// 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.
- (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;
 
@end
 
@interface ZFPlayerController (ZFPlayerOrientationRotation)
 
@property (nonatomic, readonly) ZFOrientationObserver *orientationObserver;
 
/// Whether automatic screen rotation is supported.
/// default is YES.
@property (nonatomic) BOOL shouldAutorotate;
 
/// 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;
 
/// Lock the screen orientation.
@property (nonatomic, getter=isLockedScreen) BOOL lockedScreen;
 
/// The statusbar hidden.
@property (nonatomic, getter=isStatusBarHidden) BOOL statusBarHidden;
 
/// 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.
- (void)enterLandscapeFullScreen:(UIInterfaceOrientation)orientation animated:(BOOL)animated;
 
/// Enter the fullScreen while the ZFFullScreenMode is ZFFullScreenModePortrait.
- (void)enterPortraitFullScreen:(BOOL)fullScreen animated:(BOOL)animated;
 
// FullScreen mode is determined by ZFFullScreenMode
- (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;
 
@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;
 
/// The list plays the container view of the player when the window is small after the player has slid off the screen.
@property (nonatomic, readonly, nullable) ZFFloatView *smallFloatView;
 
/// The indexPath is playing.
@property (nonatomic, readonly, nullable) NSIndexPath *playingIndexPath;
 
/// The view tag that the player display in scrollView.
@property (nonatomic, readonly) NSInteger containerViewTag;
 
/// Does the currently playing cell stop playing when the cell has slid off the screen,defalut is YES.
@property (nonatomic) BOOL stopWhileNotVisible;
 
/// Whether the small window is displayed.
@property (nonatomic, readonly) BOOL isSmallFloatViewShow;
 
/// if tableView or collectionView has more section, use sectionAssetURLs.
@property (nonatomic, copy, nullable) NSArray <NSArray <NSURL *>*>*sectionAssetURLs;
 
/// stop the current playing video on cell.
- (void)stopCurrentPlayingCell;
 
/// Play the indexPath of url, while the `assetURLs` or `sectionAssetURLs` is not NULL.
/// `scrollToTop` scroll the current cell to top with animations.
- (void)playTheIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop;
 
/// Play the indexPath with assetURL.
/// `assetURL` is the player URL.
/// `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.
/// `scrollToTop` scroll the current cell to top with animations.
/// Scroll completion callback.
- (void)playTheIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop completionHandler:(void (^ __nullable)(void))completionHandler;
 
@end
 
NS_ASSUME_NONNULL_END