ifish/Ifish/controllers/IfishYooseeFile/IfishYooseeControlller/IfishP2PPlayBack/PlayBackViewController.m

216 lines
6.3 KiB
Objective-C

//
// PlayBackViewController.m
// Ifish
//
// Created by 祝发冬 on 2020/10/18.
// Copyright © 2020 lianlian. All rights reserved.
//
#import "PlayBackViewController.h"
@interface PlayBackViewController ()<GWP2PPlayerProtocol>
@property (nonatomic, strong) GWP2PPlaybackPlayer *player;//摄像头页面
@property (nonatomic) BOOL isReject;
@end
@implementation PlayBackViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.hidden=YES;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[AppDelegate sharedDefault].canFullScreen = YES;
[self setTitleString:@"视频回放"];
UIBarButtonItem*bat=[CommonUtils ItemWithTitle:@"切换" target:self action:@selector(varyOritation) titleColor:[UIColor whiteColor]];
self.navigationItem.rightBarButtonItems=nil;
self.navigationItem.rightBarButtonItem=bat;
self.view.backgroundColor=[UIColor blackColor];
UITapGestureRecognizer*tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(taptochange)];
[self.view addGestureRecognizer:tap];
[CommonUtils interfaceOrientation:UIDeviceOrientationLandscapeRight];
[self connectDevice];
// Do any additional setup after loading the view from its nib.
}
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
}
-(void)playFiles
{
//添加播放器VC
self.player = [[GWP2PPlaybackPlayer alloc] init];
self.player.mute = YES;
self.player.delegate=self;
self.player.viewController.view.backgroundColor = [UIColor clearColor];
self.player.viewController.view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
self.player.viewController.view.frame=self.playView.bounds;
[self addChildViewController:self.player.viewController];
[self.playView addSubview:self.player.viewController.view];
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
WEAK_SELF;
[self.player p2pCallPlaybackFileWithDeviceId:self.camera.cameraId password:self.camera.cameraPass playbackFile:self.model calling:^(NSDictionary *parameters) {
} accept:^(NSDictionary *parameters) {
} reject:^(GWP2PCallError error, NSString *errorCode) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
[weakSelf.view makeToast:@"连接失败请重试!"];
weakSelf.retryBtn.hidden=NO;
[AppDelegate sharedDefault].canFullScreen = NO;
[CommonUtils interfaceOrientation:UIDeviceOrientationPortrait];
});
} ready:^{
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
weakSelf.retryBtn.hidden=YES;
});
}] ;
;
}
-(void)connectDevice{
UserModel *model=[dataContorl getUserInfo];
NSString *userIDName=[NSString stringWithFormat:@"%d",(int)[model.gwellUserID integerValue]&0x7fffffff];
//初始化设备
if ([GWP2PClient sharedClient].linkStatus != P2PLinkStatusOK) {
NSLog(@"正在检查P2P连接状态");
BOOL connectDevice = [[GWP2PClient sharedClient] connectWithAccount:userIDName codeStr1:model.P2PVerifyCode1 codeStr2:model.P2PVerifyCode2 sessionID1:model.sessionID sessionID2:model.sessionID2 customerIDs:nil];
if (connectDevice) {
[self playFiles];
}else{
[self retry:nil];
}
}
else
{
[self playFiles];
}
}
-(BOOL)p2pPlayer:(GWP2PPlayer *)player shouldHandlerSwipeGesture:(UIGestureRecognizer *)gesture
{
return YES;;
}
-(void)goBackAction{
[self.player p2pPause];
self.player=nil;
[self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)retry:(UIButton *)sender {
[self.player p2pStop];
[self.player.viewController.view removeFromSuperview];
self.player=nil;
[self connectDevice];
}
-(void)taptochange
{
self.navigationController.navigationBar.hidden=!self.navigationController.navigationBar.hidden;
[[UIApplication sharedApplication] setStatusBarHidden:self.navigationController.navigationBar.isHidden];
}
-(void)dealloc
{
self.navigationController.navigationBar.hidden=NO;
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[AppDelegate sharedDefault].canFullScreen = NO;
[CommonUtils interfaceOrientation:UIInterfaceOrientationPortrait];
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
#pragma mark 一开始希望的屏幕方向
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIDeviceOrientationLandscapeRight;
}
#pragma mark - 屏幕旋转
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
}
}
-(BOOL)shouldAutorotate
{
return YES;;
}
-(BOOL)prefersStatusBarHidden
{
return self.navigationController.isNavigationBarHidden;
}
-(void)varyOritation
{
UIInterfaceOrientation statusBarOrientation = [UIApplication sharedApplication].statusBarOrientation;
if (statusBarOrientation==UIInterfaceOrientationPortrait)
{
[AppDelegate sharedDefault].canFullScreen = YES;
[CommonUtils interfaceOrientation:UIDeviceOrientationLandscapeRight];
}
else
{
[AppDelegate sharedDefault].canFullScreen = NO;
[CommonUtils interfaceOrientation:UIDeviceOrientationPortrait];
}
}
@end