|
//
// TPMovieControls.m
// ThePaperBase
//
// Created by zhousan on 16/1/5.
// Copyright © 2016年 scar1900. All rights reserved.
//
#import "TPMovieControls.h"
@interface TPMovieControls () <ALAirplayViewDelegate>
@end
@implementation TPMovieControls
- (void)setup {
_durationSlider = [[UISlider alloc] init];
_durationSlider.value = 0.f;
_durationSlider.continuous = YES;
[_durationSlider setThumbImage:Image(@"video/sliderThumb.png") forState:UIControlStateNormal];
[_durationSlider addTarget:self action:@selector(durationSliderValueChanged:) forControlEvents:UIControlEventValueChanged];
[_durationSlider addTarget:self action:@selector(durationSliderTouchBegan:) forControlEvents:UIControlEventTouchDown];
[_durationSlider addTarget:self action:@selector(durationSliderTouchEnded:) forControlEvents:UIControlEventTouchUpInside];
[_durationSlider addTarget:self action:@selector(durationSliderTouchEnded:) forControlEvents:UIControlEventTouchUpOutside];
_timeElapsedLabel = [[UILabel alloc] init];
_timeElapsedLabel.backgroundColor = [UIColor clearColor];
_timeElapsedLabel.font = appFont(11.f, NO);
_timeElapsedLabel.textColor = [UIColor lightTextColor];
_timeElapsedLabel.textAlignment = NSTextAlignmentRight;
_timeElapsedLabel.text = @"00:00";
_timeElapsedLabel.layer.shadowColor = [UIColor blackColor].CGColor;
_timeElapsedLabel.layer.shadowRadius = 1.f;
_timeElapsedLabel.layer.shadowOffset = CGSizeMake(1.f, 1.f);
_timeElapsedLabel.layer.shadowOpacity = 0.8f;
_timeRemainingLabel = [[UILabel alloc] init];
_timeRemainingLabel.backgroundColor = [UIColor clearColor];
_timeRemainingLabel.font = appFont(11.f, NO);
_timeRemainingLabel.textColor = [UIColor lightTextColor];
_timeRemainingLabel.textAlignment = NSTextAlignmentRight;
_timeRemainingLabel.text = @"/00:00";
_timeRemainingLabel.layer.shadowColor = [UIColor blackColor].CGColor;
_timeRemainingLabel.layer.shadowRadius = 1.f;
_timeRemainingLabel.layer.shadowOffset = CGSizeMake(1.f, 1.f);
_timeRemainingLabel.layer.shadowOpacity = 0.8f;
[self addSubview:_durationSlider];
[self addSubview:_timeElapsedLabel];
[self addSubview:_timeRemainingLabel];
// _fullscreenButton = [[ALButton alloc] init];
// [_fullscreenButton setImage:Image(@"video/inFullScreen.png") forState:UIControlStateNormal];
// [_fullscreenButton setImage:Image(@"video/outFullScreen.png") forState:UIControlStateSelected];
// [_fullscreenButton addTarget:self action:@selector(fullscreenPressed:) forControlEvents:UIControlEventTouchUpInside];
// _closeButton = [[ALButton alloc]init];
// [_closeButton setImage:Image(@"video/closeBtn.png") forState:UIControlStateNormal];
// _closeButton.delegate = self;
// [_closeButton addTarget:self action:@selector(closeHandler:) forControlEvents:UIControlEventTouchUpInside];
// _closeButton.alpha = 1.0f;
/**
* bug:0005018(iPhone6查看新闻内的视频时,没有用于退出视频的‘返回键’)
*/
// [self addSubview:_closeButton];
//static stuff
// _playPauseButton = [[ALButton alloc] init];
// [_playPauseButton setImage:Image(@"video/pauseBtn.png") forState:UIControlStateNormal];
// [_playPauseButton setImage:Image(@"video/playBtn.png") forState:UIControlStateSelected];
// [_playPauseButton addTarget:self action:@selector(playPausePressed:) forControlEvents:UIControlEventTouchUpInside];
// _playPauseButton.delegate = self;
// [self addSubview:_playPauseButton];
_airplayView = [[ALAirplayView alloc] init];
_airplayView.delegate = self;
[self addSubview:_airplayView];
_activityBackgroundView = [[UIView alloc] init];
[_activityBackgroundView setBackgroundColor:[UIColor blackColor]];
_activityBackgroundView.alpha = 0.f;
_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_activityIndicator.alpha = 0.f;
_activityIndicator.hidesWhenStopped = YES;
[self addSubview:self.cutPhotoBtn];
[self.cutPhotoBtn makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.right).offset(-12);
make.centerY.equalTo(self);
make.size.mas_equalTo(CGSizeMake(25, 25));
}];
}
- (UIButton *)cutPhotoBtn {
if (!_cutPhotoBtn) {
_cutPhotoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_cutPhotoBtn setImage:Image(@"video/photoCut.png") forState:UIControlStateNormal];
self.cutPhotoBtn.hidden = YES;
}
return _cutPhotoBtn;
}
- (void)airplayButtonTouchedDown {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideControls:) object:nil];
}
- (void)airplayButtonTouchedUpOutside {
[self performSelector:@selector(hideControls:) withObject:nil afterDelay:5.0f];
}
- (void)airplayButtonTouchFailed {
[self performSelector:@selector(hideControls:) withObject:nil afterDelay:5.0f];
}
- (void)airplayButtonTouchedUpInside {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideControls:) object:nil];
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
if (!keyWindow) {
keyWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKey:) name:UIWindowDidBecomeKeyNotification object:nil];
}
@end
|