Skip to content

Commit

Permalink
Images demonstrate
Browse files Browse the repository at this point in the history
  • Loading branch information
renzifeng committed Mar 6, 2016
1 parent a4c41d3 commit bae79d5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
1 change: 1 addition & 0 deletions Player.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
TargetAttributes = {
4947F7891BE996AC003093C8 = {
CreatedOnToolsVersion = 7.0;
DevelopmentTeam = XMR2WH3HMS;
};
4947F7A21BE996AC003093C8 = {
CreatedOnToolsVersion = 7.0;
Expand Down
36 changes: 27 additions & 9 deletions Player/PlayerView/ZFPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ @interface ZFPlayerView () <XXNibBridge>
@property (nonatomic, assign) PanDirection panDirection;
/** 是否为全屏 */
@property (nonatomic, assign) BOOL isFullScreen;
// 是否在调节音量
@property (nonatomic, assign) BOOL isVolume;


@end
Expand All @@ -69,7 +71,6 @@ - (void)dealloc

-(void)layoutSubviews
{
NSLog(@"layoutSubviews==%@",NSStringFromCGRect(self.bounds));
self.playerLayer.frame = self.bounds;
}

Expand Down Expand Up @@ -395,6 +396,9 @@ - (void)fullScreenAction:(UIButton *)sender
#pragma mark - 平移手势方法
- (void)panDirection:(UIPanGestureRecognizer *)pan
{
CGPoint locationPoint = [pan locationInView:self];
NSLog(@"========%@",NSStringFromCGPoint(locationPoint));

// 我们要响应水平移动和垂直移动
// 根据上次和本次移动的位置,算出一个速率的point
CGPoint veloctyPoint = [pan velocityInView:self];
Expand All @@ -410,8 +414,6 @@ - (void)panDirection:(UIPanGestureRecognizer *)pan
self.panDirection = PanDirectionHorizontalMoved;
// 取消隐藏
self.horizontalLabel.hidden = NO;
// 模拟点击
//[self tapAction];
// 给sumTime初值
CMTime time = self.player.currentTime;
self.sumTime = time.value/time.timescale;
Expand All @@ -420,7 +422,11 @@ - (void)panDirection:(UIPanGestureRecognizer *)pan
else if (x < y){ // 垂直移动
self.panDirection = PanDirectionVerticalMoved;
// 显示音量控件

if (locationPoint.x > self.bounds.size.width / 2) {
self.isVolume = YES;
}else { // 显示亮度调节
self.isVolume = NO;
}
// 开始滑动的时候,状态改为正在控制音量

}
Expand All @@ -447,7 +453,6 @@ - (void)panDirection:(UIPanGestureRecognizer *)pan
switch (self.panDirection) {
case PanDirectionHorizontalMoved:{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

// 隐藏视图
self.horizontalLabel.hidden = YES;
});
Expand All @@ -459,6 +464,9 @@ - (void)panDirection:(UIPanGestureRecognizer *)pan
[_player pause];

[_player seekToTime:dragedCMTime completionHandler:^(BOOL finish){
//快进、快退时候把开始播放按钮改为播放状态
self.maskView.startBtn.selected = YES;
[self startAction:self.maskView.startBtn];
// ⚠️在滑动结束后,视屏要跳转
[_player play];

Expand All @@ -471,6 +479,10 @@ - (void)panDirection:(UIPanGestureRecognizer *)pan
case PanDirectionVerticalMoved:{
// 垂直移动结束后,隐藏音量控件
// 且,把状态改为不再控制音量
self.isVolume = NO;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.horizontalLabel.hidden = YES;
});
break;
}
default:
Expand All @@ -486,10 +498,16 @@ - (void)panDirection:(UIPanGestureRecognizer *)pan
#pragma mark - pan垂直移动的方法
- (void)verticalMoved:(CGFloat)value
{
// 更改系统的音量
self.volumeViewSlider.value -= value / 10000; // 越小幅度越小
//亮度
//[UIScreen mainScreen].brightness = 0.5;
if (self.isVolume) {
// 更改系统的音量
self.volumeViewSlider.value -= value / 10000; // 越小幅度越小
}else {
//亮度
[UIScreen mainScreen].brightness -= value / 10000;
NSString *brightness = [NSString stringWithFormat:@"亮度%.0f%%",[UIScreen mainScreen].brightness/1.0*100];
self.horizontalLabel.hidden = NO;
self.horizontalLabel.text = brightness;
}
}

#pragma mark - pan水平移动的方法
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# ZFPlayer
## 基于AVPlayer
## 基于AVPlayer,实现了各大视频软件的功能
* 支持横竖屏切换
* 支持本地视频、网络视频播放
* 上下滑动调节音量(模拟器调不了音量,请在真机调试)
* 左侧1/2位置上下滑动调节屏幕亮度(模拟器调不了亮度,请在真机调试)
* 右侧1/2位置上下滑动调节音量(模拟器调不了音量,请在真机调试)
* 左右滑动调节播放进度


### 图片效果演示

![图片效果演示](https://github.com/renzifeng/ZFPlayer/raw/master/screen.gif)

![声音调节演示](https://github.com/renzifeng/ZFPlayer/raw/master/volume.png)

![亮度调节演示](https://github.com/renzifeng/ZFPlayer/raw/master/brightness.png)

### ps:本人最近swift做的项目,朋友们给点建议吧:
[知乎日报Swift](https://github.com/renzifeng/ZFZhiHuDaily)

Expand Down
Binary file added brightness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added volume.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bae79d5

Please sign in to comment.