Bläddra i källkod

1.竖屏的悬浮图标逻辑

huangxiaodong 10 månader sedan
förälder
incheckning
2c8fe08d1b

+ 12 - 0
创维盒子/双子星云手机.xcodeproj/project.pbxproj

@@ -428,6 +428,10 @@
 		6B3AD68B2BF4AE630096D6B7 /* backupsOptionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B3AD6892BF4AE630096D6B7 /* backupsOptionViewController.m */; };
 		6B3AD68C2BF4AE630096D6B7 /* backupsOptionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B3AD6892BF4AE630096D6B7 /* backupsOptionViewController.m */; };
 		6B3AD68D2BF4AE630096D6B7 /* backupsOptionViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B3AD6882BF4AE630096D6B7 /* backupsOptionViewController.h */; };
+		6B3E7A6E2C89479000B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B3E7A6C2C89478A00B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.h */; };
+		6B3E7A6F2C89479000B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B3E7A6D2C89478A00B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.m */; };
+		6B3E7A702C89479300B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B3E7A6C2C89478A00B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.h */; };
+		6B3E7A712C89479300B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B3E7A6D2C89478A00B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.m */; };
 		6B3F96342AD2A15A008E349E /* netWorkManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B3F96322AD2A15A008E349E /* netWorkManager.h */; };
 		6B3F96352AD2A15A008E349E /* netWorkManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B3F96332AD2A15A008E349E /* netWorkManager.m */; };
 		6B3F963A2AD2AD0B008E349E /* newWorkInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B3F96392AD2AD0B008E349E /* newWorkInterface.h */; };
@@ -1762,6 +1766,8 @@
 		6B3AD6832BF48DBA0096D6B7 /* shareRecordDetailsHWViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = shareRecordDetailsHWViewController.m; sourceTree = "<group>"; };
 		6B3AD6882BF4AE630096D6B7 /* backupsOptionViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = backupsOptionViewController.h; sourceTree = "<group>"; };
 		6B3AD6892BF4AE630096D6B7 /* backupsOptionViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = backupsOptionViewController.m; sourceTree = "<group>"; };
+		6B3E7A6C2C89478A00B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "webRtcPlayerViewController+AdjustBtnFrame.h"; sourceTree = "<group>"; };
+		6B3E7A6D2C89478A00B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "webRtcPlayerViewController+AdjustBtnFrame.m"; sourceTree = "<group>"; };
 		6B3F96322AD2A15A008E349E /* netWorkManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = netWorkManager.h; sourceTree = "<group>"; };
 		6B3F96332AD2A15A008E349E /* netWorkManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = netWorkManager.m; sourceTree = "<group>"; };
 		6B3F96392AD2AD0B008E349E /* newWorkInterface.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = newWorkInterface.h; sourceTree = "<group>"; };
@@ -3341,6 +3347,8 @@
 				6B8676812C855EDF00F81DFC /* WebRTC.framework */,
 				6B86768E2C858CB300F81DFC /* webRtcPlayerViewController.h */,
 				6B86768F2C858CB300F81DFC /* webRtcPlayerViewController.m */,
+				6B3E7A6C2C89478A00B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.h */,
+				6B3E7A6D2C89478A00B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.m */,
 			);
 			path = webRtc;
 			sourceTree = "<group>";
@@ -3920,6 +3928,7 @@
 				6BBB35DD2AE76AD800E4A59B /* AudioSessionObject.h in Headers */,
 				6B2C1EA02C070ADE00FDCF82 /* ZFPortraitViewController.h in Headers */,
 				6B9283672C4B62A30098CC75 /* newerGuideView.h in Headers */,
+				6B3E7A6E2C89479000B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.h in Headers */,
 				6B0582782AFF7C6D00D37290 /* TZAssetModel+imageData.h in Headers */,
 				6B8661DD2BBA578600B19846 /* HaveNoticeView.h in Headers */,
 				6B5D403F2B4CE40F000965CF /* downloadManager.h in Headers */,
@@ -4199,6 +4208,7 @@
 				6BD506A42B9576A4006E7CB0 /* AudioSessionObject.h in Headers */,
 				6B2C1EA12C070ADE00FDCF82 /* ZFPortraitViewController.h in Headers */,
 				6B9283682C4B62A30098CC75 /* newerGuideView.h in Headers */,
+				6B3E7A702C89479300B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.h in Headers */,
 				6BD506A52B9576A4006E7CB0 /* TZAssetModel+imageData.h in Headers */,
 				6B8661DE2BBA578600B19846 /* HaveNoticeView.h in Headers */,
 				6BD506A62B9576A4006E7CB0 /* downloadManager.h in Headers */,
@@ -4980,6 +4990,7 @@
 				6BD5075B2B9576A4006E7CB0 /* couldphoneSysInfoModel.m in Sources */,
 				6B2C1E512C070ADE00FDCF82 /* ZFUtilities.m in Sources */,
 				6BD5075C2B9576A4006E7CB0 /* BGTool.m in Sources */,
+				6B3E7A712C89479300B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.m in Sources */,
 				6B34DC682BF1FFB1002DD1EF /* imageCollectionViewCell.m in Sources */,
 				6BD5075D2B9576A4006E7CB0 /* JSONModelClassProperty.m in Sources */,
 				6BD5075E2B9576A4006E7CB0 /* uploadFileManager.m in Sources */,
@@ -5341,6 +5352,7 @@
 				6B21708D2B14BDAA00656670 /* couldphoneSysInfoModel.m in Sources */,
 				6B2C1E502C070ADE00FDCF82 /* ZFUtilities.m in Sources */,
 				A08A94FE27E9A4E400C544BB /* BGTool.m in Sources */,
+				6B3E7A6F2C89479000B032C4 /* webRtcPlayerViewController+AdjustBtnFrame.m in Sources */,
 				6B34DC662BF1FFB1002DD1EF /* imageCollectionViewCell.m in Sources */,
 				183AE6072A89CE3C00B11CB0 /* JSONModelClassProperty.m in Sources */,
 				6B0582862B0457C400D37290 /* uploadFileManager.m in Sources */,

+ 3 - 0
创维盒子/双子星云手机/Base/Controller/BaseViewController.h

@@ -36,6 +36,9 @@ NS_ASSUME_NONNULL_BEGIN
 -(void)showNewIndicatorHaveStrWithCanBack:(BOOL)canBack canTouch:(BOOL)canTouch showText:(NSString *)text;
 -(void)removeNewIndicatorHaveStr;
 
+#pragma mark 禁用和开始右滑返回手势
+- (void)enablePanRightBack;
+- (void)noEnablePanRightBack;
 @end
 
 NS_ASSUME_NONNULL_END

+ 23 - 0
创维盒子/双子星云手机/Base/Controller/BaseViewController.m

@@ -371,4 +371,27 @@
     });
 }
 
+#pragma mark 禁用和开始右滑返回手势
+- (void)enablePanRightBack
+{
+    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
+        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
+    }
+    
+    if ([self.tabBarController.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
+        self.tabBarController.navigationController.interactivePopGestureRecognizer.enabled = YES;
+    }
+}
+
+- (void)noEnablePanRightBack
+{
+    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
+        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
+    }
+    
+    if ([self.tabBarController.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
+        self.tabBarController.navigationController.interactivePopGestureRecognizer.enabled = NO;
+    }
+}
+
 @end

+ 24 - 0
创维盒子/双子星云手机/webRtc/webRtcPlayerViewController+AdjustBtnFrame.h

@@ -0,0 +1,24 @@
+//
+//  webRtcPlayerViewController+AdjustBtnFrame.h
+//  双子星云手机
+//
+//  Created by xd h on 2024/9/5.
+//
+
+#import <Foundation/Foundation.h>
+#import "webRtcPlayerViewController.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface webRtcPlayerViewController (AdjustBtnFrame)
+{
+    
+}
+
+@property NSInteger          adjustTime;/**3s后 圆形浮标自动靠边隐藏*/
+- (void)extensionAdjustBtnFrameCheckAdjustTime;
+#pragma mark 悬浮标拖拽
+- (void)controlBtnPanGestureCallback:(UIPanGestureRecognizer *)panGesture;
+@end
+
+NS_ASSUME_NONNULL_END

+ 179 - 0
创维盒子/双子星云手机/webRtc/webRtcPlayerViewController+AdjustBtnFrame.m

@@ -0,0 +1,179 @@
+//
+//  webRtcPlayerViewController+AdjustBtnFrame.m
+//  双子星云手机
+//
+//  Created by xd h on 2024/9/5.
+//
+
+#import "webRtcPlayerViewController+AdjustBtnFrame.h"
+#import <objc/runtime.h>
+
+
+@implementation webRtcPlayerViewController(AdjustBtnFrame)
+@dynamic adjustTime;
+
+- (void)setAdjustTime:(NSInteger)adjustTime {
+    objc_setAssociatedObject(self, @selector(adjustTime), @(adjustTime), OBJC_ASSOCIATION_ASSIGN);
+}
+
+- (NSInteger)adjustTime {
+    NSNumber *adjustTimeNumber =  objc_getAssociatedObject(self, @selector(adjustTime));
+    
+    return [adjustTimeNumber integerValue];
+}
+
+#pragma mark 悬浮球3s后自动靠边隐藏
+
+
+// 控制按钮3s后 自动靠边算法
+- (void)adjustPlayerViewControlBtnFrame1 {
+    
+    CGFloat margin = 60/2.0;
+    CGFloat W_H = 60;
+    self.controlBtn.alpha = 0.5;
+    
+    CGPoint centerPoint = self.controlBtn.center;
+//    HLog(@"云手机推流界面 控制按钮中点%@",NSStringFromCGPoint(centerPoint));
+    
+    if (self.mediaStream.hw_w > self.mediaStream.hw_h){//横屏
+        CGFloat centerY = self.mediaStream.hw_h*0.5;
+        CGFloat value1Y =  centerY - centerPoint.y;
+        //CGFloat adaptValue =  (SCREEN_W - mPlayerView.glkshowImageView.hw_h)*0.5; // 补偿刘海屏上下黑边
+        
+        if (value1Y >= 0) { // 左边
+            HLog(@"云手机推流界面 靠上边");
+            self.controlBtn.hw_y = - W_H + margin;
+        }else { // 右边
+            HLog(@"云手机推流界面 靠下边");
+            self.controlBtn.hw_y = SCREEN_H - margin;
+        }
+        
+        if (self.controlBtn.hw_x < margin){
+            self.controlBtn.hw_x = margin;
+        }else if (self.controlBtn.hw_x > self.mediaStream.hw_w - margin - W_H){
+            self.controlBtn.hw_x = self.mediaStream.hw_w - margin - W_H;
+        }
+        
+    }else{//竖屏
+        //竖屏靠边状态 不处理
+        if(centerPoint.x == 0 || centerPoint.x == SCREEN_W){
+            return;
+        }
+        
+        CGFloat centerX = SCREEN_W*0.5;
+        CGFloat value1X =  centerX - centerPoint.x;
+        
+        if (value1X >= 0) { // 左边
+            HLog(@"云手机推流界面 靠左边");
+            self.controlBtn.hw_x = - W_H + margin;
+        }else { // 右边
+            HLog(@"云手机推流界面 靠右边");
+            self.controlBtn.hw_x = SCREEN_W - margin;
+        }
+        
+        //原来Y坐标逻辑
+//        if (self.controlBtn.y < margin){
+//            self.controlBtn.y = margin;
+//        }else if (self.controlBtn.y > self.mediaStream.height - margin - W_H){
+//            self.controlBtn.y = self.mediaStream.height - margin - W_H;
+//        }
+       
+        //20240905 Y坐标逻辑
+//        if(centerPoint.y < (self.mediaStream.hw_y + margin)){//在屏幕上方 超出了推流页
+//            self.controlBtn.hw_y = self.mediaStream.hw_y + margin;
+//        }
+//        else if(centerPoint.y > (self.mediaStream.hw_max_y)
+//                && (SCREEN_H - centerPoint.y) < safeArea){//在屏幕下方 超出了推流页
+//            self.controlBtn.hw_y = self.mediaStream.hw_h - margin;
+//        }
+//        else{//在屏幕中间
+//            //Y 不变
+//        }
+    }
+
+
+    HLog(@"云手机推流界面 控制按钮中点%@",NSStringFromCGPoint(self.controlBtn.center));
+}
+
+
+// 1、悬浮球3s后 自动靠边隐藏
+- (void)extensionAdjustBtnFrameCheckAdjustTime {
+    self.adjustTime--;
+    
+    if(self.adjustTime < 0){
+        self.adjustTime = 0;
+    }
+    
+    if (self.adjustTime == 0) {
+//        HLog(@"云手机圆形浮标自动隐藏倒计时 3s倒计时结束");
+        [self adjustPlayerViewControlBtnFrame1];
+    }else {
+//        HLog(@"云手机圆形浮标自动隐藏倒计时:%zd", self.adjustTime);
+    }
+}
+
+#pragma mark 悬浮标拖拽
+- (void)controlBtnPanGestureCallback:(UIPanGestureRecognizer *)panGesture{
+    self.controlBtn.alpha = 1;
+    CGRect frame = self.controlBtn.frame;
+    switch (panGesture.state) {
+        case UIGestureRecognizerStateBegan:{
+            startFrame = self.controlBtn.frame;
+            break;
+        }
+        case UIGestureRecognizerStateChanged:{
+            self.adjustTime = 2;
+            CGPoint translatedPoint = [panGesture translationInView:self.mediaStream];/*KXLY*/
+            CGRect frame = self.controlBtn.frame;
+            frame.origin.x = translatedPoint.x + startFrame.origin.x;
+            frame.origin.y = translatedPoint.y + startFrame.origin.y;
+            self.controlBtn.frame = frame;
+            
+//            HLog(@"\n--(%f,%f)--controlBtn.frame--X-%f",translatedPoint.x,translatedPoint.x,controlBtn.frame.origin.x);
+            
+            break;
+        }
+        case UIGestureRecognizerStateEnded:{
+            self.adjustTime = 1;
+            //                HLog(@"云手机推流界面 控制按钮拖动手势结束");
+            /*防止控制器移出屏幕*/
+            if (frame.origin.x < 10.f/2.f){
+                frame.origin.x = 10.f/2.f;
+            }
+            if (frame.origin.y < 10.f/2.f + H_STATE_BAR){
+                frame.origin.y = 10.f/2.f + H_STATE_BAR;
+            }
+            if (frame.size.width + frame.origin.x + 10.f/2.f > self.view.hw_w){
+                frame.origin.x = self.view.hw_w - 10.f/2.f - frame.size.width;
+            }
+            if (frame.size.height + frame.origin.y + 10.f/2.f > self.view.hw_h){
+                frame.origin.y = self.view.hw_h - 10.f/2.f - frame.size.height;
+            }
+            
+            self.controlBtn.frame = frame;
+        }
+            break;
+        case UIGestureRecognizerStateCancelled: {
+            /*防止控制器移出屏幕*/
+            if (frame.origin.x < 10.f/2.f){
+                frame.origin.x = 10.f/2.f;
+            }
+            if (frame.origin.y < 10.f/2.f + H_STATE_BAR){
+                frame.origin.y = 10.f/2.f + H_STATE_BAR;
+            }
+            if (frame.size.width + frame.origin.x + 10.f/2.f > self.view.hw_w){
+                frame.origin.x = self.view.hw_w - 10.f/2.f - frame.size.width;
+            }
+            if (frame.size.height + frame.origin.y + 10.f/2.f > self.view.hw_h){
+                frame.origin.y = self.view.hw_h - 10.f/2.f - frame.size.height;
+            }
+            
+            self.controlBtn.frame = frame;
+                        
+            break;
+        }
+        default:
+            break;
+    }
+}
+@end

+ 10 - 0
创维盒子/双子星云手机/webRtc/webRtcPlayerViewController.h

@@ -6,10 +6,20 @@
 //
 
 #import "BaseViewController.h"
+#import <WebRTC/AMediaStream.h>
+#import <WebRTC/RTCMacros.h>
+#import "UIView+HWCategory.h"
 #import "webRtcMsgModel.h"
+
 NS_ASSUME_NONNULL_BEGIN
 
 @interface webRtcPlayerViewController : BaseViewController
+{
+     CGRect startFrame;//悬浮标拖拽用
+}
+@property (nonatomic, strong) AMediaStream *mediaStream;
+@property(nonatomic,strong)UIButton    *controlBtn;
+
 @property (nonatomic,strong) webRtcMsgModel * webRtcMsgMod;
 
 @end

+ 54 - 7
创维盒子/双子星云手机/webRtc/webRtcPlayerViewController.m

@@ -6,13 +6,13 @@
 //
 
 #import "webRtcPlayerViewController.h"
-#import <WebRTC/AMediaStream.h>
-#import <WebRTC/RTCMacros.h>
-#import "UIView+View.h"
+#import "webRtcPlayerViewController+AdjustBtnFrame.h"
 
 @interface webRtcPlayerViewController ()<MediaStreamClientEventsDelegate>
-@property (nonatomic, strong) AMediaStream *mediaStream;
-@property(nonatomic,strong)UIButton    *controlBtn;
+
+@property (nonatomic, copy)   NSTimer      *playerSecondTimer; // 定时器-控制按钮
+@property (nonatomic, assign) NSInteger          concentTime; // 拉流数据 渲染更新时间戳 /**30s后 渲染时间戳无更新 自动断开链接*/
+
 @end
 
 @implementation webRtcPlayerViewController
@@ -29,10 +29,26 @@
    
 }
 
+- (void)viewWillAppear:(BOOL)animated {
+    [super viewWillAppear:animated];
+
+    // 屏幕常亮
+    [UIApplication sharedApplication].idleTimerDisabled = YES;
+    [[UIApplication sharedApplication] setStatusBarHidden:YES];
+    
+}
+
+- (void)viewDidAppear:(BOOL)animated
+{
+    [super viewDidAppear:animated];
+    [self noEnablePanRightBack];
+}
+
 - (void)viewDidDisappear:(BOOL)animated{
     [super viewDidDisappear:animated];
     
     [_mediaStream disconnect];
+    [self enablePanRightBack];
 }
 
 - (void)setWebRtcMsgMod:(webRtcMsgModel *)webRtcMsgMod
@@ -92,6 +108,7 @@
     [self showNewIndicatorWithCanBack:YES canTouch:NO];
     
     [self initBaseUIFun];
+    [self setTimerCountDown];
 }
 
 #pragma mark 初始化其他UI
@@ -107,6 +124,12 @@
            forControlEvents:(UIControlEventTouchUpInside)];
     
     [self.view addSubview:controlBtn];
+    
+    //拖拽事件等
+    UIPanGestureRecognizer *gester = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(controlBtnPanGestureCallback:)];
+    [controlBtn addGestureRecognizer:gester];
+    //gester.delegate = self;
+    
     [self initPointForControlBtnFun];
 }
 
@@ -115,8 +138,8 @@
 {
     CGFloat h_w_controlBtn = 60.f;
     /*区分横竖屏*/
-    if (_mediaStream.width > _mediaStream.height){
-        [controlBtn setFrame:CGRectMake((_mediaStream.width - h_w_controlBtn)/2.f, _mediaStream.height - h_w_controlBtn - 20.f, h_w_controlBtn, h_w_controlBtn)];
+    if (_mediaStream.hw_w > _mediaStream.hw_h){
+        [controlBtn setFrame:CGRectMake((_mediaStream.hw_w - h_w_controlBtn)/2.f, _mediaStream.hw_h - h_w_controlBtn - 20.f, h_w_controlBtn, h_w_controlBtn)];
     }else{
         //默认居右
         //[mPlayerView.controlBtn setFrame:CGRectMake(mPlayerView.width - h_w_controlBtn - 20.f, (SCREEN_H - h_w_controlBtn)/2.f, h_w_controlBtn, h_w_controlBtn)];
@@ -128,6 +151,30 @@
 
 }
 
+#pragma mark 定时器
+- (void)setTimerCountDown {
+    HLog(@"开启一个");
+    
+    if (_playerSecondTimer) {
+        // 取消定时器
+        [_playerSecondTimer invalidate];
+        _playerSecondTimer = nil;
+    }
+    
+    // 初始化值计时数据
+    //self.adjustTime = 1;
+    self.concentTime = [iTools getNowTimeStamp];
+ 
+    _playerSecondTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
+    [[NSRunLoop currentRunLoop] addTimer:_playerSecondTimer forMode:NSRunLoopCommonModes];
+}
+
+#pragma mark 定时器响应事件
+- (void)timerChange {
+    [self extensionAdjustBtnFrameCheckAdjustTime];// 1、悬浮球3s后 自动靠边隐藏
+    //[self checkConcentTime];// 3、30s之后 没有收到拉流数据 自动断开链接
+}
+
 #pragma mark 控制按钮点击事件
 - (void)controlBtnPressed:(UIButton*)but
 {