mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-10 16:29:55 +00:00
added muting property and delegate callback to override video tapping
This commit is contained in:
parent
af37a48421
commit
2d1499ab4f
@ -1616,6 +1616,7 @@
|
|||||||
058D09B9195D04C000B7D73C /* Frameworks */,
|
058D09B9195D04C000B7D73C /* Frameworks */,
|
||||||
058D09BA195D04C000B7D73C /* Resources */,
|
058D09BA195D04C000B7D73C /* Resources */,
|
||||||
3B9D88CDF51B429C8409E4B6 /* Copy Pods Resources */,
|
3B9D88CDF51B429C8409E4B6 /* Copy Pods Resources */,
|
||||||
|
FB42E06CF915B60406431170 /* Embed Pods Frameworks */,
|
||||||
);
|
);
|
||||||
buildRules = (
|
buildRules = (
|
||||||
);
|
);
|
||||||
@ -1745,6 +1746,21 @@
|
|||||||
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests-resources.sh\"\n";
|
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests-resources.sh\"\n";
|
||||||
showEnvVarsInLog = 0;
|
showEnvVarsInLog = 0;
|
||||||
};
|
};
|
||||||
|
FB42E06CF915B60406431170 /* Embed Pods Frameworks */ = {
|
||||||
|
isa = PBXShellScriptBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
inputPaths = (
|
||||||
|
);
|
||||||
|
name = "Embed Pods Frameworks";
|
||||||
|
outputPaths = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
shellPath = /bin/sh;
|
||||||
|
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests-frameworks.sh\"\n";
|
||||||
|
showEnvVarsInLog = 0;
|
||||||
|
};
|
||||||
/* End PBXShellScriptBuildPhase section */
|
/* End PBXShellScriptBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXSourcesBuildPhase section */
|
/* Begin PBXSourcesBuildPhase section */
|
||||||
|
|||||||
@ -24,6 +24,8 @@
|
|||||||
@property (nonatomic, assign, readwrite) BOOL shouldAutoplay;
|
@property (nonatomic, assign, readwrite) BOOL shouldAutoplay;
|
||||||
@property (nonatomic, assign, readwrite) BOOL shouldAutorepeat;
|
@property (nonatomic, assign, readwrite) BOOL shouldAutorepeat;
|
||||||
|
|
||||||
|
@property (nonatomic, assign, readwrite) BOOL muted;
|
||||||
|
|
||||||
@property (atomic) NSString *gravity;
|
@property (atomic) NSString *gravity;
|
||||||
@property (atomic) ASButtonNode *playButton;
|
@property (atomic) ASButtonNode *playButton;
|
||||||
|
|
||||||
@ -39,5 +41,6 @@
|
|||||||
@protocol ASVideoNodeDelegate <NSObject>
|
@protocol ASVideoNodeDelegate <NSObject>
|
||||||
@optional
|
@optional
|
||||||
- (void)videoPlaybackDidFinish:(ASVideoNode *)videoNode;
|
- (void)videoPlaybackDidFinish:(ASVideoNode *)videoNode;
|
||||||
|
- (void)videoNodeWasTapped:(ASVideoNode *)videoNode;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
BOOL _shouldAutorepeat;
|
BOOL _shouldAutorepeat;
|
||||||
BOOL _shouldAutoplay;
|
BOOL _shouldAutoplay;
|
||||||
|
|
||||||
|
BOOL _muted;
|
||||||
|
|
||||||
AVAsset *_asset;
|
AVAsset *_asset;
|
||||||
|
|
||||||
@ -31,6 +33,7 @@
|
|||||||
ASDisplayNode *_playerNode;
|
ASDisplayNode *_playerNode;
|
||||||
ASDisplayNode *_spinner;
|
ASDisplayNode *_spinner;
|
||||||
NSString *_gravity;
|
NSString *_gravity;
|
||||||
|
|
||||||
dispatch_queue_t _previewQueue;
|
dispatch_queue_t _previewQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,6 +140,7 @@
|
|||||||
AVPlayerLayer *playerLayer = [[AVPlayerLayer alloc] init];
|
AVPlayerLayer *playerLayer = [[AVPlayerLayer alloc] init];
|
||||||
if (!_player) {
|
if (!_player) {
|
||||||
_player = [AVPlayer playerWithPlayerItem:[[AVPlayerItem alloc] initWithAsset:_asset]];
|
_player = [AVPlayer playerWithPlayerItem:[[AVPlayerItem alloc] initWithAsset:_asset]];
|
||||||
|
_player.muted = _muted;
|
||||||
}
|
}
|
||||||
playerLayer.player = _player;
|
playerLayer.player = _player;
|
||||||
playerLayer.videoGravity = [self gravity];
|
playerLayer.videoGravity = [self gravity];
|
||||||
@ -176,10 +180,14 @@
|
|||||||
|
|
||||||
- (void)tapped
|
- (void)tapped
|
||||||
{
|
{
|
||||||
if (_shouldBePlaying) {
|
if (self.delegate && [self.delegate respondsToSelector:@selector(videoNodeWasTapped:)]) {
|
||||||
[self pause];
|
[self.delegate videoNodeWasTapped:self];
|
||||||
} else {
|
} else {
|
||||||
[self play];
|
if (_shouldBePlaying) {
|
||||||
|
[self pause];
|
||||||
|
} else {
|
||||||
|
[self play];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,11 +217,11 @@
|
|||||||
[_player replaceCurrentItemWithPlayerItem:_currentItem];
|
[_player replaceCurrentItemWithPlayerItem:_currentItem];
|
||||||
} else {
|
} else {
|
||||||
_player = [[AVPlayer alloc] initWithPlayerItem:_currentItem];
|
_player = [[AVPlayer alloc] initWithPlayerItem:_currentItem];
|
||||||
|
_player.muted = _muted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)clearFetchedData
|
- (void)clearFetchedData
|
||||||
{
|
{
|
||||||
[super clearFetchedData];
|
[super clearFetchedData];
|
||||||
@ -231,11 +239,14 @@
|
|||||||
|
|
||||||
if (_shouldAutoplay && _playerNode.isNodeLoaded) {
|
if (_shouldAutoplay && _playerNode.isNodeLoaded) {
|
||||||
[self play];
|
[self play];
|
||||||
|
} else if (_shouldAutoplay) {
|
||||||
|
_shouldBePlaying = YES;
|
||||||
}
|
}
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
if (_playerNode.isNodeLoaded) {
|
if (_playerNode.isNodeLoaded) {
|
||||||
if (!_player) {
|
if (!_player) {
|
||||||
_player = [AVPlayer playerWithPlayerItem:[[AVPlayerItem alloc] initWithAsset:_asset]];
|
_player = [AVPlayer playerWithPlayerItem:[[AVPlayerItem alloc] initWithAsset:_asset]];
|
||||||
|
_player.muted = _muted;
|
||||||
}
|
}
|
||||||
((AVPlayerLayer *)_playerNode.layer).player = _player;
|
((AVPlayerLayer *)_playerNode.layer).player = _player;
|
||||||
}
|
}
|
||||||
@ -256,7 +267,7 @@
|
|||||||
|
|
||||||
[self addSubnode:playButton];
|
[self addSubnode:playButton];
|
||||||
|
|
||||||
[_playButton addTarget:self action:@selector(play) forControlEvents:ASControlNodeEventTouchUpInside];
|
[_playButton addTarget:self action:@selector(tapped) forControlEvents:ASControlNodeEventTouchUpInside];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ASButtonNode *)playButton
|
- (ASButtonNode *)playButton
|
||||||
@ -310,6 +321,20 @@
|
|||||||
return _gravity;
|
return _gravity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)muted
|
||||||
|
{
|
||||||
|
ASDN::MutexLocker l(_lock);
|
||||||
|
|
||||||
|
return _muted;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setMuted:(BOOL)muted
|
||||||
|
{
|
||||||
|
ASDN::MutexLocker l(_lock);
|
||||||
|
|
||||||
|
_muted = muted;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Video Playback
|
#pragma mark - Video Playback
|
||||||
|
|
||||||
- (void)play
|
- (void)play
|
||||||
@ -330,6 +355,7 @@
|
|||||||
AVPlayerLayer *playerLayer = [[AVPlayerLayer alloc] init];
|
AVPlayerLayer *playerLayer = [[AVPlayerLayer alloc] init];
|
||||||
if (!_player) {
|
if (!_player) {
|
||||||
_player = [AVPlayer playerWithPlayerItem:[[AVPlayerItem alloc] initWithAsset:_asset]];
|
_player = [AVPlayer playerWithPlayerItem:[[AVPlayerItem alloc] initWithAsset:_asset]];
|
||||||
|
_player.muted = _muted;
|
||||||
}
|
}
|
||||||
playerLayer.player = _player;
|
playerLayer.player = _player;
|
||||||
playerLayer.videoGravity = [self gravity];
|
playerLayer.videoGravity = [self gravity];
|
||||||
|
|||||||
@ -44,7 +44,6 @@
|
|||||||
// Circle Drawing
|
// Circle Drawing
|
||||||
UIBezierPath *ovalPath = [UIBezierPath bezierPathWithOvalInRect: buttonBounds];
|
UIBezierPath *ovalPath = [UIBezierPath bezierPathWithOvalInRect: buttonBounds];
|
||||||
[[UIColor colorWithWhite:0.0 alpha:0.5] setFill];
|
[[UIColor colorWithWhite:0.0 alpha:0.5] setFill];
|
||||||
[ovalPath stroke];
|
|
||||||
[ovalPath fill];
|
[ovalPath fill];
|
||||||
|
|
||||||
// Triangle Drawing
|
// Triangle Drawing
|
||||||
|
|||||||
@ -43,7 +43,6 @@
|
|||||||
|
|
||||||
videoNode.backgroundColor = [UIColor lightGrayColor];
|
videoNode.backgroundColor = [UIColor lightGrayColor];
|
||||||
|
|
||||||
// videoNode.playButton = [self playButton];
|
|
||||||
return videoNode;
|
return videoNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +60,8 @@
|
|||||||
|
|
||||||
nicCageVideo.backgroundColor = [UIColor lightGrayColor];
|
nicCageVideo.backgroundColor = [UIColor lightGrayColor];
|
||||||
nicCageVideo.shouldAutorepeat = YES;
|
nicCageVideo.shouldAutorepeat = YES;
|
||||||
// nicCageVideo.playButton = [self playButton];
|
nicCageVideo.shouldAutoplay = YES;
|
||||||
|
nicCageVideo.muted = YES;
|
||||||
|
|
||||||
return nicCageVideo;
|
return nicCageVideo;
|
||||||
}
|
}
|
||||||
@ -79,7 +79,6 @@
|
|||||||
|
|
||||||
simonVideo.backgroundColor = [UIColor lightGrayColor];
|
simonVideo.backgroundColor = [UIColor lightGrayColor];
|
||||||
simonVideo.shouldAutorepeat = YES;
|
simonVideo.shouldAutorepeat = YES;
|
||||||
// simonVideo.playButton = [self playButton];
|
|
||||||
simonVideo.shouldAutoplay = YES;
|
simonVideo.shouldAutoplay = YES;
|
||||||
|
|
||||||
return simonVideo;
|
return simonVideo;
|
||||||
@ -99,6 +98,15 @@
|
|||||||
return playButton;
|
return playButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)videoNodeWasTapped:(ASVideoNode *)videoNode
|
||||||
|
{
|
||||||
|
if (videoNode.player.muted == YES) {
|
||||||
|
videoNode.player.muted = NO;
|
||||||
|
} else {
|
||||||
|
videoNode.player.muted = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)prefersStatusBarHidden
|
- (BOOL)prefersStatusBarHidden
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user