mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
enable/disable controls
This commit is contained in:
@@ -31,6 +31,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
@property (nonatomic,assign,readonly) CMTime duration;
|
@property (nonatomic,assign,readonly) CMTime duration;
|
||||||
|
|
||||||
|
@property (nonatomic, assign) BOOL disableControls;
|
||||||
|
|
||||||
- (instancetype)initWithUrl:(NSURL*)url;
|
- (instancetype)initWithUrl:(NSURL*)url;
|
||||||
- (instancetype)initWithAsset:(AVAsset*)asset;
|
- (instancetype)initWithAsset:(AVAsset*)asset;
|
||||||
|
|
||||||
@@ -108,7 +110,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
* @abstract Delegate method invoked when the ASVideoNode has played to its end time.
|
* @abstract Delegate method invoked when the ASVideoNode has played to its end time.
|
||||||
* @param videoPlayerNode The video node has played to its end time.
|
* @param videoPlayerNode The video node has played to its end time.
|
||||||
*/
|
*/
|
||||||
- (void)videoPlayerNodePlaybackDidFinish:(ASVideoPlayerNode *)videoPlayer;
|
- (void)videoPlayerNodeDidPlayToEnd:(ASVideoPlayerNode *)videoPlayer;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
|
|||||||
AVAsset *_asset;
|
AVAsset *_asset;
|
||||||
|
|
||||||
ASVideoNode *_videoNode;
|
ASVideoNode *_videoNode;
|
||||||
|
|
||||||
ASDisplayNode *_controlsHolderNode;
|
|
||||||
|
|
||||||
NSArray *_neededControls;
|
NSArray *_neededControls;
|
||||||
|
|
||||||
@@ -51,6 +49,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
|
|||||||
BOOL _isSeeking;
|
BOOL _isSeeking;
|
||||||
CMTime _duration;
|
CMTime _duration;
|
||||||
|
|
||||||
|
BOOL _disableControls;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -88,6 +87,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
|
|||||||
}
|
}
|
||||||
|
|
||||||
_asset = asset;
|
_asset = asset;
|
||||||
|
_disableControls = NO;
|
||||||
|
|
||||||
[self privateInit];
|
[self privateInit];
|
||||||
|
|
||||||
@@ -104,10 +104,6 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
|
|||||||
_videoNode.delegate = self;
|
_videoNode.delegate = self;
|
||||||
[self addSubnode:_videoNode];
|
[self addSubnode:_videoNode];
|
||||||
|
|
||||||
_controlsHolderNode = [[ASDisplayNode alloc] init];
|
|
||||||
_controlsHolderNode.backgroundColor = [UIColor greenColor];
|
|
||||||
[self addSubnode:_controlsHolderNode];
|
|
||||||
|
|
||||||
[self addObservers];
|
[self addObservers];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,10 +143,18 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
|
|||||||
{
|
{
|
||||||
ASDN::MutexLocker l(_videoPlayerLock);
|
ASDN::MutexLocker l(_videoPlayerLock);
|
||||||
|
|
||||||
|
if (_disableControls) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_neededControls == nil) {
|
if (_neededControls == nil) {
|
||||||
_neededControls = [self createControlElementArray];
|
_neededControls = [self createControlElementArray];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_cachedControls == nil) {
|
||||||
|
_cachedControls = [[NSMutableDictionary alloc] init];
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < _neededControls.count; i++) {
|
for (int i = 0; i < _neededControls.count; i++) {
|
||||||
ASVideoPlayerNodeControlType type = (ASVideoPlayerNodeControlType)[[_neededControls objectAtIndex:i] integerValue];
|
ASVideoPlayerNodeControlType type = (ASVideoPlayerNodeControlType)[[_neededControls objectAtIndex:i] integerValue];
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -173,17 +177,31 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASPerformBlockOnMainThread(^{
|
||||||
|
ASDN::MutexLocker l(_videoPlayerLock);
|
||||||
|
[self setNeedsLayout];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeControls
|
- (void)removeControls
|
||||||
{
|
{
|
||||||
NSArray *controls = [_cachedControls allValues];
|
NSArray *controls = [_cachedControls allValues];
|
||||||
[controls enumerateObjectsUsingBlock:^(ASDisplayNode *_Nonnull node, NSUInteger idx, BOOL * _Nonnull stop) {
|
[controls enumerateObjectsUsingBlock:^(ASDisplayNode *_Nonnull node, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||||
[node.view removeFromSuperview];
|
|
||||||
[node removeFromSupernode];
|
[node removeFromSupernode];
|
||||||
//node = nil;
|
|
||||||
NSLog(@"%@",_playbackButtonNode);
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
[self cleanCachedControls];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)cleanCachedControls
|
||||||
|
{
|
||||||
|
[_cachedControls removeAllObjects];
|
||||||
|
|
||||||
|
_playbackButtonNode = nil;
|
||||||
|
_elapsedTextNode = nil;
|
||||||
|
_durationTextNode = nil;
|
||||||
|
_scrubberNode = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)createPlaybackButton
|
- (void)createPlaybackButton
|
||||||
@@ -348,7 +366,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
|
|||||||
- (void)videoPlaybackDidFinish:(ASVideoNode *)videoNode
|
- (void)videoPlaybackDidFinish:(ASVideoNode *)videoNode
|
||||||
{
|
{
|
||||||
if (_delegateFlags.delegateVideoNodePlaybackDidFinish) {
|
if (_delegateFlags.delegateVideoNodePlaybackDidFinish) {
|
||||||
[_delegate videoPlayerNodePlaybackDidFinish:self];
|
[_delegate videoPlayerNodeDidPlayToEnd:self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,12 +502,23 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
|
|||||||
_delegateFlags.delegateLayoutSpecForControls = [_delegate respondsToSelector:@selector(videoPlayerNodeLayoutSpec:forControls:forConstrainedSize:)];
|
_delegateFlags.delegateLayoutSpecForControls = [_delegate respondsToSelector:@selector(videoPlayerNodeLayoutSpec:forControls:forConstrainedSize:)];
|
||||||
_delegateFlags.delegateVideoNodeDidPlayToTime = [_delegate respondsToSelector:@selector(videoPlayerNode:didPlayToTime:)];
|
_delegateFlags.delegateVideoNodeDidPlayToTime = [_delegate respondsToSelector:@selector(videoPlayerNode:didPlayToTime:)];
|
||||||
_delegateFlags.delegateVideoNodeWillChangeState = [_delegate respondsToSelector:@selector(videoPlayerNode:willChangeVideoNodeState:toVideoNodeState:)];
|
_delegateFlags.delegateVideoNodeWillChangeState = [_delegate respondsToSelector:@selector(videoPlayerNode:willChangeVideoNodeState:toVideoNodeState:)];
|
||||||
_delegateFlags.delegateVideoNodePlaybackDidFinish = [_delegate respondsToSelector:@selector(videoPlayerNodePlaybackDidFinish:)];
|
_delegateFlags.delegateVideoNodePlaybackDidFinish = [_delegate respondsToSelector:@selector(videoPlayerNodeDidPlayToEnd:)];
|
||||||
_delegateFlags.delegateVideoNodeShouldChangeState = [_delegate respondsToSelector:@selector(videoPlayerNode:shouldChangeVideoNodeStateTo:)];
|
_delegateFlags.delegateVideoNodeShouldChangeState = [_delegate respondsToSelector:@selector(videoPlayerNode:shouldChangeVideoNodeStateTo:)];
|
||||||
_delegateFlags.delegateTimeLabelAttributedString = [_delegate respondsToSelector:@selector(videoPlayerNode:timeStringForTimeLabelType:forTime:)];
|
_delegateFlags.delegateTimeLabelAttributedString = [_delegate respondsToSelector:@selector(videoPlayerNode:timeStringForTimeLabelType:forTime:)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setDisableControls:(BOOL)disableControls
|
||||||
|
{
|
||||||
|
_disableControls = disableControls;
|
||||||
|
|
||||||
|
if (_disableControls && _cachedControls.count > 0) {
|
||||||
|
[self removeControls];
|
||||||
|
} else if (!_disableControls) {
|
||||||
|
[self createControls];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Helpers
|
#pragma mark - Helpers
|
||||||
- (NSString *)timeStringForCMTime:(CMTime)time forTimeLabelType:(ASVideoPlayerNodeControlType)type
|
- (NSString *)timeStringForCMTime:(CMTime)time forTimeLabelType:(ASVideoPlayerNodeControlType)type
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,6 +45,11 @@
|
|||||||
|
|
||||||
_videoPlayerNode = [[ASVideoPlayerNode alloc] initWithUrl:fileUrl];
|
_videoPlayerNode = [[ASVideoPlayerNode alloc] initWithUrl:fileUrl];
|
||||||
_videoPlayerNode.delegate = self;
|
_videoPlayerNode.delegate = self;
|
||||||
|
// _videoPlayerNode.disableControls = YES;
|
||||||
|
//
|
||||||
|
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||||
|
// _videoPlayerNode.disableControls = NO;
|
||||||
|
// });
|
||||||
|
|
||||||
_videoPlayerNode.backgroundColor = [UIColor blackColor];
|
_videoPlayerNode.backgroundColor = [UIColor blackColor];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user