Skip to content

Commit

Permalink
Merge branch 'release/2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
defagos committed May 8, 2018
2 parents bbc9e13 + 681a7f5 commit 0f25c5d
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 49 deletions.
1 change: 1 addition & 0 deletions Framework/Sources/Overlays/SRGAirplayButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ - (void)prepareForInterfaceBuilder
UIButton *fakeInterfaceBuilderButton = [UIButton buttonWithType:UIButtonTypeSystem];
fakeInterfaceBuilderButton.frame = self.bounds;
fakeInterfaceBuilderButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
fakeInterfaceBuilderButton.imageView.contentMode = UIViewContentModeScaleAspectFill;
[fakeInterfaceBuilderButton setImage:self.image forState:UIControlStateNormal];
[self addSubview:fakeInterfaceBuilderButton];
self.fakeInterfaceBuilderButton = fakeInterfaceBuilderButton;
Expand Down
4 changes: 2 additions & 2 deletions Framework/Sources/Overlays/SRGPictureInPictureButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,9 @@ - (void)srg_pictureInPictureButton_togglePictureInPicture:(id)sender

if (pictureInPictureController.pictureInPictureActive) {
[pictureInPictureController stopPictureInPicture];
[self.button setImage:self.startImage forState:UIControlStateNormal];
}
else {
[pictureInPictureController startPictureInPicture];
[self.button setImage:self.stopImage forState:UIControlStateNormal];
}
}

Expand All @@ -185,6 +183,7 @@ - (void)prepareForInterfaceBuilder
UIButton *fakeInterfaceBuilderButton = [UIButton buttonWithType:UIButtonTypeSystem];
fakeInterfaceBuilderButton.frame = self.bounds;
fakeInterfaceBuilderButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
fakeInterfaceBuilderButton.imageView.contentMode = UIViewContentModeScaleAspectFill;
[fakeInterfaceBuilderButton setImage:self.startImage forState:UIControlStateNormal];
[self addSubview:fakeInterfaceBuilderButton];
self.fakeInterfaceBuilderButton = fakeInterfaceBuilderButton;
Expand Down Expand Up @@ -231,6 +230,7 @@ static void commonInit(SRGPictureInPictureButton *self)
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = self.bounds;
button.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
button.imageView.contentMode = UIViewContentModeScaleAspectFill;
[button addTarget:self action:@selector(srg_pictureInPictureButton_togglePictureInPicture:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
self.button = button;
Expand Down
6 changes: 2 additions & 4 deletions Framework/Sources/Overlays/SRGTimeSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ typedef NS_ENUM(NSInteger, SRGTimeSliderLiveKnobPosition) {
* can also bind two labels for displaying the time and the remaining time.
*
* Slider colors can be customized as follows:
* - `borderColor`: Color of the small border around the non-elapsed time track (defaults to black) and of the
* preloading progress bar.
* - `minimumTrackTintColor`: Elapsed time track color (defaults to white).
* - `maximumTrackTintColor`: Remaining time track color (defaults to black).
* - `thumbTintColor`: Thumb color (defaults to white).
Expand Down Expand Up @@ -63,9 +61,9 @@ IB_DESIGNABLE
@property (nonatomic, weak, nullable) IBOutlet UILabel *valueLabel;

/**
* Bar border color (defaults to black).
* The thickness of the slider track. Defaults to 3, minimum is 1.
*/
@property (nonatomic, null_resettable) IBInspectable UIColor *borderColor;
@property (nonatomic) IBInspectable CGFloat trackThickness;

/**
* Buffering bar color (defaults to dark gray).
Expand Down
90 changes: 49 additions & 41 deletions Framework/Sources/Overlays/SRGTimeSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
static NSString *SRGTimeSliderAccessibilityFormatter(NSTimeInterval seconds)
{
if (isnan(seconds) || isinf(seconds)) {
return nil;
return nil;
}

static NSDateComponentsFormatter *s_dateComponentsFormatter;
Expand All @@ -64,6 +64,8 @@ @interface SRGTimeSlider ()
@property (nonatomic) UIColor *overriddenMaximumTrackTintColor;
@property (nonatomic) UIColor *overriddenMinimumTrackTintColor;

@property (nonatomic) NSArray<NSValue *> *previousLoadedTimeRanges;

@end

@implementation SRGTimeSlider
Expand Down Expand Up @@ -136,9 +138,14 @@ - (BOOL)isDraggable
return self.minimumValue != self.maximumValue;
}

- (void)setBorderColor:(UIColor *)borderColor
- (void)setTrackThickness:(CGFloat)trackThickness
{
_borderColor = borderColor ?: [UIColor blackColor];
if (trackThickness >= 1.f) {
_trackThickness = trackThickness;
}
else {
_trackThickness = 1.f;
}
}

- (void)setBufferingTrackColor:(UIColor *)bufferingTrackColor
Expand Down Expand Up @@ -286,7 +293,6 @@ - (BOOL)isLive
- (BOOL)isReadyToDisplayValues
{
AVPlayerItem *playerItem = self.mediaPlayerController.player.currentItem;

return (playerItem && self.mediaPlayerController.playbackState != SRGMediaPlayerPlaybackStateIdle
&& self.mediaPlayerController.playbackState != SRGMediaPlayerPlaybackStateEnded
&& playerItem.status == AVPlayerItemStatusReadyToPlay
Expand Down Expand Up @@ -428,60 +434,61 @@ - (void)drawRect:(CGRect)rect
[super drawRect:rect];

CGContextRef context = UIGraphicsGetCurrentContext();
[self drawBar:context];
[self drawMaximumTrack:context];
[self drawMinimumTrack:context];
}

- (void)drawBar:(CGContextRef)context
{
CGRect trackFrame = [self trackRectForBounds:self.bounds];

CGFloat lineWidth = 3.f;
void (^drawTimeRanges)(NSArray<NSValue *> *) = ^(NSArray<NSValue *> *timeRanges) {
for (NSValue *value in timeRanges) {
CMTimeRange timeRange = [value CMTimeRangeValue];
[self drawBufferingTrackForRange:timeRange context:context];
}
};

CGContextSetLineWidth(context, lineWidth);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextMoveToPoint(context, CGRectGetMinX(trackFrame), CGRectGetMidY(self.bounds));
CGContextAddLineToPoint(context, CGRectGetWidth(trackFrame), CGRectGetMidY(self.bounds));
CGContextSetStrokeColorWithColor(context, self.borderColor.CGColor);
CGContextStrokePath(context);
// In general, draw all loaded time ranges
if (self.mediaPlayerController.playbackState != SRGMediaPlayerPlaybackStateSeeking) {
NSArray<NSValue *> *loadedTimeRanges = self.mediaPlayerController.player.currentItem.loadedTimeRanges;
drawTimeRanges(loadedTimeRanges);
self.previousLoadedTimeRanges = loadedTimeRanges;
}
// If the player is seeking, find whether the player is seeking within one of the previous time ranges we
// were displaying (though it might change during the seek). While this remains true, display the same ranges
// as before (even if they are not perfectly up to date), so that the track never jumps erratically.
else {
for (NSValue *timeRange in self.previousLoadedTimeRanges) {
if (CMTimeRangeContainsTime(timeRange.CMTimeRangeValue, self.time)) {
drawTimeRanges(self.previousLoadedTimeRanges);
return;
}
}
}
}

- (void)drawMaximumTrack:(CGContextRef)context
{
CGRect trackFrame = [self trackRectForBounds:self.bounds];

CGFloat lineWidth = 1.f;
CGRect trackFrame = [self maximumValueImageRectForBounds:self.bounds];

CGContextSetLineWidth(context, lineWidth);
CGContextSetLineCap(context, kCGLineCapButt);
CGContextMoveToPoint(context, CGRectGetMinX(trackFrame) + 2.f, CGRectGetMidY(self.bounds));
CGContextAddLineToPoint(context, CGRectGetMaxX(trackFrame) - 2.f, CGRectGetMidY(self.bounds));
CGContextSetLineWidth(context, self.trackThickness);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextMoveToPoint(context, CGRectGetMinX(trackFrame), CGRectGetMidY(self.bounds));
CGContextAddLineToPoint(context, CGRectGetMaxX(trackFrame), CGRectGetMidY(self.bounds));
CGContextSetStrokeColorWithColor(context, self.maximumTrackTintColor.CGColor);
CGContextStrokePath(context);

for (NSValue *value in self.mediaPlayerController.player.currentItem.loadedTimeRanges) {
CMTimeRange timeRange = [value CMTimeRangeValue];
[self drawBuferringTrackForRange:timeRange context:context];
}
}

- (void)drawBuferringTrackForRange:(CMTimeRange)timeRange context:(CGContextRef)context
- (void)drawBufferingTrackForRange:(CMTimeRange)timeRange context:(CGContextRef)context
{
CGFloat lineWidth = 1.f;

CGFloat duration = CMTimeGetSeconds(self.mediaPlayerController.player.currentItem.duration);
if (isnan(duration)) {
return;
}

CGRect trackFrame = [self trackRectForBounds:self.bounds];

CGFloat minX = CGRectGetWidth(trackFrame) / duration * CMTimeGetSeconds(timeRange.start);
CGFloat maxX = CGRectGetWidth(trackFrame) / duration * (CMTimeGetSeconds(timeRange.start) + CMTimeGetSeconds(timeRange.duration));
CGFloat minX = CGRectGetMinX(trackFrame) + CGRectGetWidth(trackFrame) / duration * CMTimeGetSeconds(timeRange.start);
CGFloat maxX = CGRectGetMinX(trackFrame) + CGRectGetWidth(trackFrame) / duration * CMTimeGetSeconds(CMTimeRangeGetEnd(timeRange));

CGContextSetLineWidth(context, lineWidth);
CGContextSetLineCap(context, kCGLineCapButt);
CGContextSetLineWidth(context, self.trackThickness);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextMoveToPoint(context, minX, CGRectGetMidY(self.bounds));
CGContextAddLineToPoint(context, maxX, CGRectGetMidY(self.bounds));
CGContextSetStrokeColorWithColor(context, self.bufferingTrackColor.CGColor);
Expand All @@ -492,11 +499,9 @@ - (void)drawMinimumTrack:(CGContextRef)context
{
CGRect barFrame = [self minimumValueImageRectForBounds:self.bounds];

CGFloat lineWidth = 3.f;

CGContextSetLineWidth(context, lineWidth);
CGContextSetLineWidth(context, self.trackThickness);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextMoveToPoint(context, CGRectGetMinX(barFrame) - 0.5f, CGRectGetMidY(self.bounds));
CGContextMoveToPoint(context, CGRectGetMinX(barFrame), CGRectGetMidY(self.bounds));
CGContextAddLineToPoint(context, CGRectGetWidth(barFrame), CGRectGetMidY(self.bounds));
CGContextSetStrokeColorWithColor(context, self.minimumTrackTintColor.CGColor);
CGContextStrokePath(context);
Expand All @@ -514,6 +519,8 @@ - (float)resetValue
- (void)srg_timeSlider_playbackStateDidChange:(NSNotification *)notification
{
if (self.mediaPlayerController.playbackState == SRGMediaPlayerPlaybackStateIdle) {
self.previousLoadedTimeRanges = nil;

float value = [self resetValue];
self.value = value;
self.maximumValue = value;
Expand Down Expand Up @@ -584,13 +591,14 @@ - (void)prepareForInterfaceBuilder
static void commonInit(SRGTimeSlider *self)
{
// Apply default colors
self.borderColor = nil;
self.bufferingTrackColor = nil;

self.minimumValue = 0.f; // Always 0
self.maximumValue = 0.f;
self.value = 0.f;

self.trackThickness = 3.f;

UIImage *triangle = [self emptyImage];
UIImage *image = [triangle resizableImageWithCapInsets:UIEdgeInsetsMake(1.f, 1.f, 1.f, 1.f)];

Expand Down
2 changes: 2 additions & 0 deletions Framework/Sources/Overlays/SRGTracksButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ - (void)prepareForInterfaceBuilder
UIButton *fakeInterfaceBuilderButton = [UIButton buttonWithType:UIButtonTypeSystem];
fakeInterfaceBuilderButton.frame = self.bounds;
fakeInterfaceBuilderButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
fakeInterfaceBuilderButton.imageView.contentMode = UIViewContentModeScaleAspectFill;
[fakeInterfaceBuilderButton setImage:self.image forState:UIControlStateNormal];
[self addSubview:fakeInterfaceBuilderButton];
self.fakeInterfaceBuilderButton = fakeInterfaceBuilderButton;
Expand Down Expand Up @@ -255,6 +256,7 @@ static void commonInit(SRGTracksButton *self)
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = self.bounds;
button.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
button.imageView.contentMode = UIViewContentModeScaleAspectFill;
[button addTarget:self action:@selector(showSubtitlesMenu:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
self.button = button;
Expand Down
2 changes: 2 additions & 0 deletions Framework/Sources/Overlays/SRGViewModeButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ - (void)prepareForInterfaceBuilder
UIButton *fakeInterfaceBuilderButton = [UIButton buttonWithType:UIButtonTypeSystem];
fakeInterfaceBuilderButton.frame = self.bounds;
fakeInterfaceBuilderButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
fakeInterfaceBuilderButton.imageView.contentMode = UIViewContentModeScaleAspectFill;
[fakeInterfaceBuilderButton setImage:self.viewModeMonoscopicImage forState:UIControlStateNormal];
[self addSubview:fakeInterfaceBuilderButton];
self.fakeInterfaceBuilderButton = fakeInterfaceBuilderButton;
Expand Down Expand Up @@ -202,6 +203,7 @@ static void commonInit(SRGViewModeButton *self)
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = self.bounds;
button.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
button.imageView.contentMode = UIViewContentModeScaleAspectFill;
[button addTarget:self action:@selector(srg_viewModeButton_toggleViewMode:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
self.button = button;
Expand Down
4 changes: 2 additions & 2 deletions SRGMediaPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MARKETING_VERSION = 2.3.2;
MARKETING_VERSION = 2.4;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -1255,7 +1255,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MARKETING_VERSION = 2.3.2;
MARKETING_VERSION = 2.4;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
Expand Down

0 comments on commit 0f25c5d

Please sign in to comment.