mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-04-04 20:52:41 +00:00
wip fixing pr comments
This commit is contained in:
@@ -212,11 +212,6 @@
|
||||
return stack;
|
||||
}
|
||||
|
||||
- (void)layoutDidFinish
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
- (void)layout
|
||||
{
|
||||
[super layout];
|
||||
|
||||
@@ -7,12 +7,13 @@ typedef NS_ENUM(NSUInteger, ASVideoGravity) {
|
||||
ASVideoGravityResize
|
||||
};
|
||||
|
||||
@interface ASVideoNode : ASDisplayNode<_ASDisplayLayerDelegate>
|
||||
@interface ASVideoNode : ASControlNode<_ASDisplayLayerDelegate>
|
||||
@property (atomic, strong, readwrite) AVAsset *asset;
|
||||
@property (nonatomic, assign, readwrite) BOOL shouldAutoPlay;
|
||||
@property (nonatomic, assign, readwrite) BOOL shouldAutoplay;
|
||||
@property (atomic) ASVideoGravity gravity;
|
||||
@property (atomic) BOOL autorepeat;
|
||||
@property (atomic) ASButtonNode *playButton;
|
||||
@property (atomic) AVPlayer *player;
|
||||
|
||||
- (void)play;
|
||||
- (void)pause;
|
||||
@@ -22,9 +23,9 @@ typedef NS_ENUM(NSUInteger, ASVideoGravity) {
|
||||
@protocol ASVideoNodeDelegate <NSObject>
|
||||
@end
|
||||
|
||||
@protocol ASVideoNodeDatasource <NSObject>
|
||||
@protocol ASVideoNodeDataSource <NSObject>
|
||||
@optional
|
||||
- (ASDisplayNode *)playButtonForVideoNode:(ASVideoNode *) videoNode;
|
||||
- (ASButtonNode *)playButtonForVideoNode:(ASVideoNode *)videoNode;
|
||||
- (UIImage *)thumbnailForVideoNode:(ASVideoNode *) videoNode;
|
||||
- (NSURL *)thumbnailURLForVideoNode:(ASVideoNode *)videoNode;
|
||||
@end
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
#import "ASVideoNode.h"
|
||||
|
||||
@interface ASVideoNode () {
|
||||
@interface ASVideoNode ()
|
||||
{
|
||||
ASDN::RecursiveMutex _lock;
|
||||
|
||||
__weak id<ASVideoNodeDatasource> _datasource;
|
||||
__weak id<ASVideoNodeDataSource> _dataSource;
|
||||
|
||||
BOOL _shouldBePlaying;
|
||||
AVAsset *_asset;
|
||||
@@ -23,7 +24,8 @@
|
||||
|
||||
@implementation ASVideoNode
|
||||
|
||||
- (instancetype)init {
|
||||
- (instancetype)init
|
||||
{
|
||||
if (!(self = [super init])) { return nil; }
|
||||
|
||||
_playerNode = [[ASDisplayNode alloc] initWithLayerBlock:^CALayer *{
|
||||
@@ -35,11 +37,14 @@
|
||||
|
||||
self.gravity = ASVideoGravityResizeAspect;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(restartVideo:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
|
||||
[self addTarget:self action:@selector(tapped) forControlEvents:ASControlNodeEventTouchUpInside];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didPlayToEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// FIXME: Adopt interfaceStateDidChange API
|
||||
- (void)setInterfaceState:(ASInterfaceState)newState
|
||||
{
|
||||
[super setInterfaceState:newState];
|
||||
@@ -51,9 +56,6 @@
|
||||
if (_shouldBePlaying) {
|
||||
[self play];
|
||||
}
|
||||
if (_spinner) {
|
||||
[self addSubnode:_spinner];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +73,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)restartVideo:(NSNotification *)notification
|
||||
- (void)didPlayToEnd:(NSNotification *)notification
|
||||
{
|
||||
if ( [[[notification object] asset] isEqual:_asset]) {
|
||||
if (ASObjectIsEqual([[notification object] asset], _asset)) {
|
||||
[[((AVPlayerLayer *)_playerNode.layer) player] seekToTime:CMTimeMakeWithSeconds(0, 1)];
|
||||
|
||||
if (_autorepeat) {
|
||||
@@ -84,18 +86,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)layoutDidFinish
|
||||
- (void)layout
|
||||
{
|
||||
[super layout];
|
||||
_playerNode.frame = self.bounds;
|
||||
}
|
||||
|
||||
- (void)didLoad {
|
||||
[super didLoad];
|
||||
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
|
||||
[self.view addGestureRecognizer:tap];
|
||||
}
|
||||
|
||||
- (void)tapped
|
||||
{
|
||||
if (_shouldBePlaying) {
|
||||
@@ -134,7 +130,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
if (_shouldAutoPlay) {
|
||||
if (_shouldAutoplay) {
|
||||
[self play];
|
||||
}
|
||||
}
|
||||
@@ -189,7 +185,8 @@
|
||||
return _asset;
|
||||
}
|
||||
|
||||
- (void)setGravity:(ASVideoGravity)gravity {
|
||||
- (void)setGravity:(ASVideoGravity)gravity
|
||||
{
|
||||
ASDN::MutexLocker l(_lock);
|
||||
|
||||
switch (gravity) {
|
||||
@@ -208,28 +205,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (ASVideoGravity)gravity;
|
||||
- (ASVideoGravity)gravity
|
||||
{
|
||||
ASDN::MutexLocker l(_lock);
|
||||
|
||||
if ([((AVPlayerLayer *)_playerNode.layer).contentsGravity isEqualToString:AVLayerVideoGravityResize]) {
|
||||
if (ASObjectIsEqual(((AVPlayerLayer *)_playerNode.layer).contentsGravity, AVLayerVideoGravityResize)) {
|
||||
return ASVideoGravityResize;
|
||||
}
|
||||
if ([((AVPlayerLayer *)_playerNode.layer).contentsGravity isEqualToString:AVLayerVideoGravityResizeAspectFill]) {
|
||||
if (ASObjectIsEqual(((AVPlayerLayer *)_playerNode.layer).contentsGravity, AVLayerVideoGravityResizeAspectFill)) {
|
||||
return ASVideoGravityResizeAspectFill;
|
||||
}
|
||||
|
||||
return ASVideoGravityResizeAspect;
|
||||
}
|
||||
|
||||
- (void)play;
|
||||
- (void)play
|
||||
{
|
||||
ASDN::MutexLocker l(_lock);
|
||||
|
||||
[[((AVPlayerLayer *)_playerNode.layer) player] play];
|
||||
_shouldBePlaying = YES;
|
||||
_playButton.alpha = 0.0;
|
||||
if ([self ready] && ![self.subnodes containsObject:_spinner]) {
|
||||
if (!_spinner) {
|
||||
_spinner = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{
|
||||
UIActivityIndicatorView *spinnnerView = [[UIActivityIndicatorView alloc] initWithFrame:_playButton.frame];
|
||||
spinnnerView.color = [UIColor whiteColor];
|
||||
@@ -237,21 +231,30 @@
|
||||
|
||||
return spinnnerView;
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
if (![self ready]) {
|
||||
[self addSubnode:_spinner];
|
||||
}
|
||||
|
||||
[[((AVPlayerLayer *)_playerNode.layer) player] play];
|
||||
_shouldBePlaying = YES;
|
||||
_playButton.alpha = 0.0;
|
||||
// if ([self ready] && ![self.subnodes containsObject:_spinner]) {
|
||||
// }
|
||||
}
|
||||
|
||||
- (BOOL)ready;
|
||||
- (BOOL)ready
|
||||
{
|
||||
return [((AVPlayerLayer *)_playerNode.layer) player].currentItem.status != AVPlayerItemStatusReadyToPlay;
|
||||
return [((AVPlayerLayer *)_playerNode.layer) player].currentItem.status == AVPlayerItemStatusReadyToPlay;
|
||||
}
|
||||
|
||||
- (void)pause;
|
||||
- (void)pause
|
||||
{
|
||||
ASDN::MutexLocker l(_lock);
|
||||
|
||||
[[((AVPlayerLayer *)_playerNode.layer) player] pause];
|
||||
[((UIActivityIndicatorView *)_spinner.view) stopAnimating];
|
||||
_shouldBePlaying = NO;
|
||||
_playButton.alpha = 1.0;
|
||||
}
|
||||
@@ -261,6 +264,16 @@
|
||||
return _currentItem;
|
||||
}
|
||||
|
||||
- (ASDisplayNode *)spinner
|
||||
{
|
||||
return _spinner;
|
||||
}
|
||||
|
||||
- (AVPlayerItem *)curentItem
|
||||
{
|
||||
return _currentItem;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
Reference in New Issue
Block a user