forked from facebookarchive/AsyncDisplayKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASVideoPlayerNode.h
More file actions
160 lines (133 loc) · 6.45 KB
/
ASVideoPlayerNode.h
File metadata and controls
160 lines (133 loc) · 6.45 KB
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
//
// ASVideoPlayerNode.h
// AsyncDisplayKit
//
// Created by Erekle on 5/6/16.
// Copyright © 2016 Facebook. All rights reserved.
//
#if TARGET_OS_IOS
#import <AsyncDisplayKit/AsyncDisplayKit.h>
//#import <AsyncDisplayKit/ASThread.h>
//#import <AsyncDisplayKit/ASVideoNode.h>
//#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
@class AVAsset;
@protocol ASVideoPlayerNodeDelegate;
typedef enum {
ASVideoPlayerNodeControlTypePlaybackButton,
ASVideoPlayerNodeControlTypeElapsedText,
ASVideoPlayerNodeControlTypeDurationText,
ASVideoPlayerNodeControlTypeScrubber,
ASVideoPlayerNodeControlTypeFlexGrowSpacer,
} ASVideoPlayerNodeControlType;
NS_ASSUME_NONNULL_BEGIN
@interface ASVideoPlayerNode : ASDisplayNode
@property (nullable, atomic, weak) id<ASVideoPlayerNodeDelegate> delegate;
@property (nonatomic, assign, readonly) CMTime duration;
@property (nonatomic, assign) BOOL controlsDisabled;
@property (nonatomic, assign, readonly) BOOL loadAssetWhenNodeBecomesVisible;
#pragma mark - ASVideoNode property proxy
/**
* When shouldAutoplay is set to true, a video node will play when it has both loaded and entered the "visible" interfaceState.
* If it leaves the visible interfaceState it will pause but will resume once it has returned.
*/
@property (nonatomic, assign, readwrite) BOOL shouldAutoPlay;
@property (nonatomic, assign, readwrite) BOOL shouldAutoRepeat;
@property (nonatomic, assign, readwrite) BOOL muted;
@property (nonatomic, assign, readonly) ASVideoNodePlayerState playerState;
@property (nonatomic, assign, readwrite) BOOL shouldAggressivelyRecoverFromStall;
//! Defaults to 100
@property (nonatomic, assign) int32_t periodicTimeObserverTimescale;
//! Defaults to AVLayerVideoGravityResizeAspect
@property (atomic) NSString *gravity;
- (instancetype)initWithUrl:(NSURL*)url;
- (instancetype)initWithAsset:(AVAsset*)asset;
- (instancetype)initWithUrl:(NSURL *)url loadAssetWhenNodeBecomesVisible:(BOOL)loadAssetWhenNodeBecomesVisible;
- (instancetype)initWithAsset:(AVAsset *)asset loadAssetWhenNodeBecomesVisible:(BOOL)loadAssetWhenNodeBecomesVisible;
#pragma mark - Public API
- (void)seekToTime:(CGFloat)percentComplete;
- (void)play;
- (void)pause;
- (BOOL)isPlaying;
@end
#pragma mark - ASVideoPlayerNodeDelegate -
@protocol ASVideoPlayerNodeDelegate <NSObject>
@optional
/**
* @abstract Delegate method invoked before creating controlbar controls
* @param videoPlayer
*/
- (NSArray *)videoPlayerNodeNeededDefaultControls:(ASVideoPlayerNode*)videoPlayer;
/**
* @abstract Delegate method invoked before creating default controls, asks delegate for custom controls dictionary.
* This dictionary must constain only ASDisplayNode subclass objects.
* @param videoPlayer
* @discussion - This method is invoked only when developer implements videoPlayerNodeLayoutSpec:forControls:forMaximumSize:
* and gives ability to add custom constrols to ASVideoPlayerNode, for example mute button.
*/
- (NSDictionary *)videoPlayerNodeCustomControls:(ASVideoPlayerNode*)videoPlayer;
/**
* @abstract Delegate method invoked in layoutSpecThatFits:
* @param videoPlayer
* @param controls - Dictionary of controls which are used in videoPlayer; Dictionary keys are ASVideoPlayerNodeControlType
* @param maxSize - Maximum size for ASVideoPlayerNode
* @discussion - Developer can layout whole ASVideoPlayerNode as he wants. ASVideoNode is locked and it can't be changed
*/
- (ASLayoutSpec *)videoPlayerNodeLayoutSpec:(ASVideoPlayerNode *)videoPlayer
forControls:(NSDictionary *)controls
forMaximumSize:(CGSize)maxSize;
#pragma mark Text delegate methods
/**
* @abstract Delegate method invoked before creating ASVideoPlayerNodeControlTypeElapsedText and ASVideoPlayerNodeControlTypeDurationText
* @param videoPlayer
* @param timeLabelType
*/
- (NSDictionary *)videoPlayerNodeTimeLabelAttributes:(ASVideoPlayerNode *)videoPlayerNode timeLabelType:(ASVideoPlayerNodeControlType)timeLabelType;
- (NSString *)videoPlayerNode:(ASVideoPlayerNode *)videoPlayerNode
timeStringForTimeLabelType:(ASVideoPlayerNodeControlType)timeLabelType
forTime:(CMTime)time;
#pragma mark Scrubber delegate methods
- (UIColor *)videoPlayerNodeScrubberMaximumTrackTint:(ASVideoPlayerNode *)videoPlayer;
- (UIColor *)videoPlayerNodeScrubberMinimumTrackTint:(ASVideoPlayerNode *)videoPlayer;
- (UIColor *)videoPlayerNodeScrubberThumbTint:(ASVideoPlayerNode *)videoPlayer;
- (UIImage *)videoPlayerNodeScrubberThumbImage:(ASVideoPlayerNode *)videoPlayer;
#pragma mark - Spinner delegate methods
- (UIColor *)videoPlayerNodeSpinnerTint:(ASVideoPlayerNode *)videoPlayer;
#pragma mark - Playback button delegate methods
- (UIColor *)videoPlayerNodePlaybackButtonTint:(ASVideoPlayerNode *)videoPlayer;
#pragma mark ASVideoNodeDelegate proxy methods
/**
* @abstract Delegate method invoked when ASVideoPlayerNode is taped.
* @param videoPlayerNode The ASVideoPlayerNode that was tapped.
*/
- (void)didTapVideoPlayerNode:(ASVideoPlayerNode *)videoPlayer;
/**
* @abstract Delegate method invoked when ASVideoNode playback time is updated.
* @param videoPlayerNode The video player node
* @param second current playback time.
*/
- (void)videoPlayerNode:(ASVideoPlayerNode *)videoPlayer didPlayToTime:(CMTime)time;
/**
* @abstract Delegate method invoked when ASVideoNode changes state.
* @param videoPlayerNode The ASVideoPlayerNode whose ASVideoNode is changing state.
* @param state ASVideoNode state before this change.
* @param toSate ASVideoNode new state.
* @discussion This method is called after each state change
*/
- (void)videoPlayerNode:(ASVideoPlayerNode *)videoPlayer willChangeVideoNodeState:(ASVideoNodePlayerState)state toVideoNodeState:(ASVideoNodePlayerState)toState;
/**
* @abstract Delegate method is invoked when ASVideoNode decides to change state.
* @param videoPlayerNode The ASVideoPlayerNode whose ASVideoNode is changing state.
* @param state ASVideoNode that is going to be set.
* @discussion Delegate method invoked when player changes it's state to
* ASVideoNodePlayerStatePlaying or ASVideoNodePlayerStatePaused
* and asks delegate if state change is valid
*/
- (BOOL)videoPlayerNode:(ASVideoPlayerNode*)videoPlayer shouldChangeVideoNodeStateTo:(ASVideoNodePlayerState)state;
/**
* @abstract Delegate method invoked when the ASVideoNode has played to its end time.
* @param videoPlayerNode The video node has played to its end time.
*/
- (void)videoPlayerNodeDidPlayToEnd:(ASVideoPlayerNode *)videoPlayer;
@end
NS_ASSUME_NONNULL_END
#endif