@implementation HBLiveStreamView
{
BOOL _isHigh;
BOOL _isLow;
CGRect overBtnFrame;
CGRect belowBtnFrame;
}
// 放两个视频分辨率按钮的view
self.resolutionView = [[UIView alloc]init];
[self.resolutionView setFrame:CGRectMake(self.width-100, self.height-93, 50, 100)];
[self.toolView addSubview:self.resolutionView];
//上面分辨率按钮 下面按钮的frame = CGRectMake(15, 60, 30, 30) 下面按钮的frame = CGRectMake(15, 30, 30, 30)
self.aboveButton = [[UIButton alloc]init];
[self.aboveButton setFrame:CGRectMake(15, 30, 30, 30)];
overBtnFrame = self.aboveButton.frame;
[self.aboveButton addTarget:self action:@selector(showHighResolutionBtn:) forControlEvents:UIControlEventTouchUpInside];
self.aboveButton.titleLabel.textColor =[UIColor whiteColor];
self.aboveButton.titleLabel.textAlignment = NSTextAlignmentCenter;
[self.aboveButton.titleLabel setFont:[UIFont systemFontOfSize:10]];
[self.aboveButton setBackgroundColor:RGBACOLOR(0, 0, 0, 0.8)];
[self.aboveButton setHidden:YES];
[self.resolutionView addSubview:self.aboveButton];
//下面分辨率按钮
self.belowButton = [[UIButton alloc]init];
[self.belowButton setFrame:CGRectMake(15, 60, 30, 30)];
belowBtnFrame = self.belowButton.frame;
[self.belowButton addTarget:self action:@selector(showLowResolutionBtn:) forControlEvents:UIControlEventTouchUpInside];
self.belowButton.titleLabel.textColor =[UIColor whiteColor];
self.belowButton.titleLabel.textAlignment = NSTextAlignmentCenter;
[self.belowButton.titleLabel setFont:[UIFont systemFontOfSize:10]];
[self.belowButton setBackgroundColor:RGBACOLOR(0, 0, 0, 0.8)];
[self.resolutionView addSubview:self.belowButton];
if([[DeviceManager shareInstace].currentCamera.resolution isEqualToString:@"720"]){//从服务器获得720P [DeviceManager shareInstace].currentCamera.resolution
[self.aboveButton setTitle:@"480P" forState:UIControlStateNormal];
[self.aboveButton setTitle:@"480P" forState:UIControlStateHighlighted];
[self.belowButton setTitle:@"720P" forState:UIControlStateNormal];
[self.belowButton setTitle:@"720P" forState:UIControlStateHighlighted];
}else{ //从服务器获得480P [DeviceManager shareInstace].currentCamera.resolution
[self.aboveButton setTitle:@"720P" forState:UIControlStateNormal];
[self.aboveButton setTitle:@"720P" forState:UIControlStateHighlighted];
[self.belowButton setTitle:@"480P" forState:UIControlStateNormal];
[self.belowButton setTitle:@"480P" forState:UIControlStateHighlighted];
}
/**
* 点击下面按钮
*/
- (void)showLowResolutionBtn:(UIButton *)btn{
if (_isHigh) { //再次点击下面,隐藏上面按钮
[self.aboveButton setHidden:YES];
if ([NSStringFromCGRect(self.belowButton.frame) isEqualToString:NSStringFromCGRect(overBtnFrame)])
{
self.belowButton.frame = belowBtnFrame;
self.aboveButton.frame = overBtnFrame;
//切换到另一种画质
[self changeResolution:btn];
}
}else{ // 初次点击下面,显示上面按钮
[self.aboveButton setHidden:NO];
}
_isHigh =!_isHigh;
}
/**
* 点击上面按钮
*/
- (void)showHighResolutionBtn:(UIButton *)btn{
if (_isLow) { //再次点击480P按钮,显示720P按钮
self.belowButton.frame = overBtnFrame;
[self.belowButton setHidden:NO];
}else{ // 初次点击,设置480下面,隐藏720P按钮
//切换到480P
if ([NSStringFromCGRect(self.aboveButton.frame) isEqualToString:NSStringFromCGRect(overBtnFrame)])
{
//切换到另一种画质
[self changeResolution:btn];
}
self.aboveButton.frame = belowBtnFrame;
[self.belowButton setHidden:YES];
}
_isLow =!_isLow;
}