mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-17 11:50:56 +00:00
_delegateFlags
added _delegateFlags like in ASCollectionView
This commit is contained in:
parent
2c2a73dc83
commit
34e6238391
@ -50,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
@property (nonatomic, assign, readonly) ASVideoNodePlayerState playerState;
|
@property (nonatomic, assign, readonly) ASVideoNodePlayerState playerState;
|
||||||
//! Defaults to 100
|
//! Defaults to 100
|
||||||
@property (nonatomic, assign, readwrite) int32_t periodicTimeObserverTimescale;
|
@property (nonatomic, assign) int32_t periodicTimeObserverTimescale;
|
||||||
|
|
||||||
//! Defaults to AVLayerVideoGravityResizeAspect
|
//! Defaults to AVLayerVideoGravityResizeAspect
|
||||||
@property (atomic) NSString *gravity;
|
@property (atomic) NSString *gravity;
|
||||||
|
|||||||
@ -36,6 +36,13 @@ static NSString * const kStatus = @"status";
|
|||||||
ASDN::RecursiveMutex _videoLock;
|
ASDN::RecursiveMutex _videoLock;
|
||||||
|
|
||||||
__weak id<ASVideoNodeDelegate> _delegate;
|
__weak id<ASVideoNodeDelegate> _delegate;
|
||||||
|
struct {
|
||||||
|
unsigned int delegateVideNodeShouldChangePlayerStateTo:1;
|
||||||
|
unsigned int delegateVideoPlaybackDidFinish:1;
|
||||||
|
unsigned int delegateVideoNodeWasTapped:1;
|
||||||
|
unsigned int delegateVideoNodeWillChangePlayerStateToState:1;
|
||||||
|
unsigned int delegateVideoNodeDidPlayToSecond:1;
|
||||||
|
} _delegateFlags;
|
||||||
|
|
||||||
BOOL _shouldBePlaying;
|
BOOL _shouldBePlaying;
|
||||||
|
|
||||||
@ -254,15 +261,16 @@ static NSString * const kStatus = @"status";
|
|||||||
}
|
}
|
||||||
} else if ([keyPath isEqualToString:kplaybackBufferEmpty]) {
|
} else if ([keyPath isEqualToString:kplaybackBufferEmpty]) {
|
||||||
if (_shouldBePlaying && [change[NSKeyValueChangeNewKey] boolValue] == true && ASInterfaceStateIncludesVisible(self.interfaceState)) {
|
if (_shouldBePlaying && [change[NSKeyValueChangeNewKey] boolValue] == true && ASInterfaceStateIncludesVisible(self.interfaceState)) {
|
||||||
[self showSpinner]; // show spinner and set ASVideoNodePlayerStateLoading
|
self.playerState = ASVideoNodePlayerStateLoading;
|
||||||
|
[self showSpinner];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tapped
|
- (void)tapped
|
||||||
{
|
{
|
||||||
if (self.delegate && [self.delegate respondsToSelector:@selector(videoNodeWasTapped:)]) {
|
if (_delegateFlags.delegateVideoNodeWasTapped) {
|
||||||
[self.delegate videoNodeWasTapped:self];
|
[_delegate videoNodeWasTapped:self];
|
||||||
} else {
|
} else {
|
||||||
if (_shouldBePlaying) {
|
if (_shouldBePlaying) {
|
||||||
[self pause];
|
[self pause];
|
||||||
@ -307,7 +315,7 @@ static NSString * const kStatus = @"status";
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_delegate && [_delegate respondsToSelector:@selector(videoNode:didPlayToSecond:)]){
|
if(_delegateFlags.delegateVideoNodeDidPlayToSecond){
|
||||||
[_delegate videoNode:self didPlayToSecond:timeInSeconds];
|
[_delegate videoNode:self didPlayToSecond:timeInSeconds];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -353,7 +361,7 @@ static NSString * const kStatus = @"status";
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([_delegate respondsToSelector:@selector(videoNode:willChangePlayerState:toState:)]) {
|
if (_delegateFlags.delegateVideoNodeWillChangePlayerStateToState) {
|
||||||
[_delegate videoNode:self willChangePlayerState:oldState toState:playerState];
|
[_delegate videoNode:self willChangePlayerState:oldState toState:playerState];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,6 +421,24 @@ static NSString * const kStatus = @"status";
|
|||||||
return _player;
|
return _player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id<ASVideoNodeDelegate>)delegate{
|
||||||
|
return _delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setDelegate:(id<ASVideoNodeDelegate>)delegate
|
||||||
|
{
|
||||||
|
_delegate = delegate;
|
||||||
|
if(_delegate == nil) {
|
||||||
|
memset(&_delegateFlags, 0, sizeof(_delegateFlags));
|
||||||
|
} else {
|
||||||
|
_delegateFlags.delegateVideNodeShouldChangePlayerStateTo = [_delegate respondsToSelector:@selector(videoNode:shouldChangePlayerStateTo:)];
|
||||||
|
_delegateFlags.delegateVideoPlaybackDidFinish = [_delegate respondsToSelector:@selector(videoPlaybackDidFinish:)];
|
||||||
|
_delegateFlags.delegateVideoNodeWasTapped = [_delegate respondsToSelector:@selector(videoNodeWasTapped:)];
|
||||||
|
_delegateFlags.delegateVideoNodeWillChangePlayerStateToState = [_delegate respondsToSelector:@selector(videoNode:willChangePlayerState:toState:)];
|
||||||
|
_delegateFlags.delegateVideoNodeDidPlayToSecond = [_delegate respondsToSelector:@selector(videoNode:didPlayToSecond:)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setGravity:(NSString *)gravity
|
- (void)setGravity:(NSString *)gravity
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(_videoLock);
|
ASDN::MutexLocker l(_videoLock);
|
||||||
@ -503,7 +529,6 @@ static NSString * const kStatus = @"status";
|
|||||||
|
|
||||||
[self addSubnode:_spinner];
|
[self addSubnode:_spinner];
|
||||||
}
|
}
|
||||||
self.playerState = ASVideoNodePlayerStateLoading;
|
|
||||||
[(UIActivityIndicatorView *)_spinner.view startAnimating];
|
[(UIActivityIndicatorView *)_spinner.view startAnimating];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -542,7 +567,7 @@ static NSString * const kStatus = @"status";
|
|||||||
|
|
||||||
- (BOOL)isStateChangeValid:(ASVideoNodePlayerState)state
|
- (BOOL)isStateChangeValid:(ASVideoNodePlayerState)state
|
||||||
{
|
{
|
||||||
if([_delegate respondsToSelector:@selector(videoNode:shouldChangePlayerStateTo:)]){
|
if(_delegateFlags.delegateVideNodeShouldChangePlayerStateTo){
|
||||||
if(![_delegate videoNode:self shouldChangePlayerStateTo:state]){
|
if(![_delegate videoNode:self shouldChangePlayerStateTo:state]){
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
@ -556,7 +581,7 @@ static NSString * const kStatus = @"status";
|
|||||||
- (void)didPlayToEnd:(NSNotification *)notification
|
- (void)didPlayToEnd:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
self.playerState = ASVideoNodePlayerStateFinished;
|
self.playerState = ASVideoNodePlayerStateFinished;
|
||||||
if ([_delegate respondsToSelector:@selector(videoPlaybackDidFinish:)]) {
|
if (_delegateFlags.delegateVideoPlaybackDidFinish) {
|
||||||
[_delegate videoPlaybackDidFinish:self];
|
[_delegate videoPlaybackDidFinish:self];
|
||||||
}
|
}
|
||||||
[_player seekToTime:kCMTimeZero];
|
[_player seekToTime:kCMTimeZero];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user