492 lines
17 KiB
Objective-C
492 lines
17 KiB
Objective-C
//
|
||
// IfishP2PPlayBackListViewController.m
|
||
// Ifish
|
||
//
|
||
// Created by imac on 16/12/6.
|
||
// Copyright © 2016年 lianxiang. All rights reserved.
|
||
//
|
||
|
||
#import "IfishP2PPlayBackListViewController.h"
|
||
#import "CameraNoParyBackVideoView.h"
|
||
#import "P2PClient.h"
|
||
#import "IfishPlaybackViewCell.h"
|
||
#import <GWP2P/GWP2P.h>
|
||
#import "DatePickerCustomView.h"
|
||
#import "PlayBackViewController.h"
|
||
#define BACKVIEW_ROWH 60
|
||
#define ANIM_VIEW_WIDTH_AND_HEIGHT 80
|
||
|
||
//新
|
||
#import "P2PPlayingbackVC.h"
|
||
@interface IfishP2PPlayBackListViewController ()<UITableViewDelegate,UITableViewDataSource,P2PPlaybackDelegate>
|
||
@property(nonatomic,strong) IBOutlet UITableView *tableView;
|
||
@property(retain, nonatomic) NSMutableArray *playbackFiles;
|
||
@property(retain, nonatomic) NSMutableArray *playbackSize;
|
||
@property(retain, nonatomic) NSMutableArray *timesData;
|
||
|
||
@property(retain, nonatomic) NSMutableArray *playbackFilesMore;
|
||
@property(retain, nonatomic) NSMutableArray *playbackSizeMore;
|
||
@property(retain, nonatomic) NSMutableArray *timesDataMore;
|
||
@property(nonatomic,strong) CameraNoParyBackVideoView *noDataView;
|
||
@property(strong, nonatomic) NSString *nextEndDate;
|
||
@property (nonatomic) BOOL hasSDCard;//是否更多
|
||
@property(strong, nonatomic) UIView *movieView;
|
||
@property (nonatomic) BOOL isInItDevice; //是否连接设备
|
||
@property (nonatomic, strong) DatePickerCustomView *datePickView;
|
||
@property (nonatomic, strong) NSDate *startDate;
|
||
@property (nonatomic, strong) NSDate *endDate;
|
||
@end
|
||
|
||
@implementation IfishP2PPlayBackListViewController
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
|
||
_hasSDCard = NO;
|
||
|
||
self.playbackFiles = [NSMutableArray arrayWithCapacity:0];
|
||
self.playbackSize = [NSMutableArray arrayWithCapacity:0];
|
||
self.playbackFilesMore = [NSMutableArray arrayWithCapacity:0];
|
||
self.playbackSizeMore = [NSMutableArray arrayWithCapacity:0];
|
||
[self addTitleViewWithTitle:@"视频回放"];
|
||
[self connectDevice];
|
||
[self initUI];
|
||
|
||
//[[P2PClient sharedClient] setPlaybackDelegate:self];
|
||
}
|
||
|
||
#pragma mark - 初始化设备 p2pConnect
|
||
|
||
-(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) {
|
||
|
||
[[GWP2PClient sharedClient] getDeviceStorageInfomationWithDeviceID:self.camera.cameraId devicePassword:self.camera.cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
|
||
|
||
if (success)
|
||
{
|
||
self.hasSDCard=YES;
|
||
[self initNoSDDataViewHidden:YES];
|
||
}
|
||
else
|
||
{
|
||
[self initNoSDDataViewHidden:NO];
|
||
}
|
||
}];
|
||
|
||
}else{
|
||
NSLog(@"p2pConnect failure.失败,不能操作设备");
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
-(void)viewWillAppear:(BOOL)animated{
|
||
[super viewWillAppear:animated];
|
||
[AppDelegate sharedDefault].canFullScreen = YES;
|
||
// [self connectDevice];
|
||
}
|
||
|
||
|
||
-(void)viewWillDisappear:(BOOL)animated{
|
||
[super viewWillDisappear:animated];
|
||
}
|
||
|
||
-(void)viewDidAppear:(BOOL)animated{
|
||
[super viewDidAppear:animated];
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
-(void)goBackAction{
|
||
|
||
// [[P2PClient sharedClient] p2pHungUp];
|
||
[self.navigationController popViewControllerAnimated:YES];
|
||
}
|
||
|
||
|
||
|
||
|
||
-(void)initNoSDDataViewHidden:(BOOL)hidden
|
||
|
||
{
|
||
if (hidden) {
|
||
|
||
[self.noDataView removeFromSuperview];
|
||
|
||
return;
|
||
}
|
||
|
||
if (!self.noDataView) {
|
||
|
||
self.noDataView = [[CameraNoParyBackVideoView alloc] initWithFrame:self.tableView.frame];
|
||
|
||
[self.view addSubview:self.noDataView];
|
||
}
|
||
|
||
UIImage *img=LXImageWithImageName(@"playback_iocn_sdk");
|
||
self.noDataView.dataType = noDataViewTypeNOSDCard;
|
||
[self.noDataView setViewData:img title:@"未检测到SD卡" subTitle:@"请将SD卡插入摄像头对应的卡槽中"];
|
||
|
||
}
|
||
|
||
-(void)initNoVideoDataViewHidden:(BOOL)hidden
|
||
{
|
||
if (!self.noDataView) {
|
||
//CGFloat viewH =200;
|
||
self.noDataView = [[CameraNoParyBackVideoView alloc] initWithFrame:self.tableView.frame];
|
||
[self.view addSubview:self.noDataView];
|
||
}
|
||
|
||
self.noDataView.dataType = noDataViewTypeNOVideo;
|
||
UIImage *img=LXImageWithImageName(@"playback_iocn_sp");
|
||
[self.noDataView setViewData:img title:@"还没有视频哦~" subTitle:@""];
|
||
self.noDataView.hidden = hidden;
|
||
|
||
|
||
}
|
||
-(void)initUI
|
||
{
|
||
NSDate *nowDate = [NSDate date]; // 当前时间
|
||
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
||
formatter.dateFormat = @"yyyy-MM-dd HH:mm";
|
||
NSString *string = [formatter stringFromDate:nowDate]; //
|
||
[self.startBtn setTitle:[formatter stringFromDate:[nowDate dateByAddingTimeInterval:-60*60]] forState:UIControlStateNormal];
|
||
[self.endBtn setTitle:string forState:UIControlStateNormal];
|
||
self.startDate=[nowDate dateByAddingTimeInterval:-60*60];
|
||
self.endDate=nowDate;
|
||
}
|
||
|
||
- (IBAction)startTimeClick:(UIButton *)sender {
|
||
|
||
[self.datePickView removeFromSuperview];
|
||
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
||
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier: @"zh_CN"]];
|
||
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
|
||
DatePickerCustomView* dateView = [DatePickerCustomView showInView:self.view Mode:UIDatePickerModeDateAndTime date:[dateFormatter dateFromString:[sender titleForState:UIControlStateNormal]]];
|
||
dateView.datePicker.maximumDate=[NSDate date];
|
||
|
||
self.datePickView=dateView;
|
||
WEAK_SELF;
|
||
|
||
__weak DatePickerCustomView* weakDateView =dateView;
|
||
dateView.dateChanged =^{
|
||
|
||
[sender setTitle:[dateFormatter stringFromDate:weakDateView.datePicker.date] forState:UIControlStateNormal];
|
||
weakSelf.startDate=weakDateView.datePicker.date;
|
||
|
||
};
|
||
dateView.cancelBlock = ^{
|
||
|
||
};
|
||
}
|
||
- (IBAction)endTimeClick:(UIButton *)sender {
|
||
|
||
[self.datePickView removeFromSuperview];
|
||
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
||
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier: @"zh_CN"]];
|
||
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
|
||
DatePickerCustomView* dateView = [DatePickerCustomView showInView:self.view Mode:UIDatePickerModeDateAndTime date:[dateFormatter dateFromString:[sender titleForState:UIControlStateNormal]]];
|
||
dateView.datePicker.maximumDate=[NSDate date];
|
||
|
||
self.datePickView=dateView;
|
||
|
||
__weak DatePickerCustomView* weakDateView =dateView;
|
||
WEAK_SELF;
|
||
dateView.dateChanged =^{
|
||
|
||
[sender setTitle:[dateFormatter stringFromDate:weakDateView.datePicker.date] forState:UIControlStateNormal];
|
||
weakSelf.endDate=weakDateView.datePicker.date;
|
||
};
|
||
dateView.cancelBlock = ^{
|
||
|
||
};
|
||
}
|
||
- (IBAction)searchClick:(UIButton *)sender {
|
||
|
||
if ([self.startDate compare:self.endDate]==NSOrderedDescending) {
|
||
[self.view makeToast:@"开始时间必须小于结束时间"];
|
||
return;;
|
||
}
|
||
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
||
[[GWP2PClient sharedClient] getDevicePlaybackFilesWithDeviceID:self.camera.cameraId devicePassword:self.camera.cameraPass startDate:self.startDate endDate:self.endDate completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
|
||
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
||
NSLog(@"dataDictionary=%@",dataDictionary);
|
||
[self.playbackFiles removeAllObjects];
|
||
if (success&&[dataDictionary[@"error value"] intValue]==0)
|
||
{
|
||
|
||
NSArray*files=dataDictionary[@"files"];
|
||
if ([files isKindOfClass:[NSArray class]]&&files.count)
|
||
{
|
||
[self initNoVideoDataViewHidden:YES];
|
||
[self.playbackFiles addObjectsFromArray:files];
|
||
|
||
[self.tableView reloadData];
|
||
}
|
||
else
|
||
{
|
||
[self initNoVideoDataViewHidden:NO];
|
||
}
|
||
}
|
||
else
|
||
{
|
||
[self initNoVideoDataViewHidden:NO];
|
||
[self connectDevice];
|
||
}
|
||
}];
|
||
}
|
||
|
||
- (void)didReceiveMemoryWarning {
|
||
[super didReceiveMemoryWarning];
|
||
// Dispose of any resources that can be recreated.
|
||
}
|
||
|
||
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
||
|
||
return 1;
|
||
|
||
}
|
||
|
||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||
return self.playbackFiles.count;
|
||
}
|
||
|
||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
||
return BACKVIEW_ROWH;
|
||
|
||
}
|
||
|
||
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
||
|
||
IfishPlaybackViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IfishPlaybackViewCell"];
|
||
GWPlaybackFileModel*model=[self.playbackFiles objectAtIndex:indexPath.row];
|
||
|
||
if (!cell) {
|
||
cell = [[[NSBundle mainBundle]loadNibNamed:@"IfishPlaybackViewCell" owner:self options:nil]lastObject];
|
||
|
||
}
|
||
cell.model=model;
|
||
|
||
|
||
|
||
return cell;
|
||
|
||
}
|
||
|
||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
||
|
||
GWPlaybackFileModel*model=[self.playbackFiles objectAtIndex:indexPath.row];
|
||
PlayBackViewController*play=[[PlayBackViewController alloc]init];
|
||
play.camera=self.camera;
|
||
play.model=model;
|
||
|
||
|
||
[self.navigationController pushViewController:play animated:YES];
|
||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||
|
||
|
||
}
|
||
//
|
||
//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
|
||
//
|
||
// if (section==0) {
|
||
// //描述 + 回放列表 + 今天 + 1 像素线
|
||
// return 50 +BACKVIEW_ROWH +BACKVIEW_ROWH + 1;
|
||
// }
|
||
// return 0.1;
|
||
//}
|
||
//
|
||
//-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
|
||
//
|
||
// if (section ==1) {
|
||
//
|
||
// return BACKVIEW_ROWH;
|
||
// }
|
||
// return 0.1;
|
||
//}
|
||
//-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
|
||
//
|
||
// CGFloat space = 10;
|
||
//
|
||
// if (section ==0) {
|
||
//
|
||
// UIView *section0Header =[[UIView alloc] init];
|
||
// section0Header.frame = CGRectMake(0, 0, self.view.frame.size.width, 191);
|
||
//
|
||
// UILabel *describleLabe=[[UILabel alloc] init];
|
||
// describleLabe.frame = CGRectMake(0, 0,self.view.frame.size.width, 50);
|
||
// describleLabe.textColor =RGB(102, 102, 102);
|
||
// describleLabe.textAlignment = NSTextAlignmentCenter;
|
||
// describleLabe.text = @"30分钟录制一次,录像最多存储7日";
|
||
// describleLabe.font = [UIFont systemFontOfSize:12];
|
||
// describleLabe.backgroundColor = RGB(241, 245, 246);
|
||
//
|
||
// [section0Header addSubview:describleLabe];
|
||
//
|
||
// UIView *listLabeBack =[[UIView alloc] init];
|
||
// listLabeBack.frame = CGRectMake(0,CGRectGetMaxY(describleLabe.frame), self.view.frame.size.width,BACKVIEW_ROWH);
|
||
// listLabeBack.backgroundColor = [UIColor whiteColor];
|
||
//
|
||
// [section0Header addSubview:listLabeBack];
|
||
//
|
||
// UILabel *listLabe=[[UILabel alloc] init];
|
||
// listLabe.frame = CGRectMake(space,CGRectGetHeight(listLabeBack.frame)/2,200, 20);
|
||
// listLabe.textColor =RGB(102, 102, 102);
|
||
// listLabe.font = [UIFont systemFontOfSize:15];
|
||
// listLabe.text = @"回放列表";
|
||
// [listLabeBack addSubview:listLabe];
|
||
// CGFloat listlW = 50;
|
||
// UILabel *listl=[[UILabel alloc] init];
|
||
// listl.frame = CGRectMake(self.view.frame.size.width - space -listlW -4,CGRectGetHeight(listLabeBack.frame)/2,listlW, 20);
|
||
// listl.textColor =RGB(102, 102, 102);
|
||
// listl.font = [UIFont systemFontOfSize:14];
|
||
// listl.text = @"时长";
|
||
// listl.textAlignment = NSTextAlignmentRight;
|
||
// [listLabeBack addSubview:listl];
|
||
//
|
||
//
|
||
// //一像素分割线
|
||
// UIView *lineView =[[UIView alloc] init];
|
||
// lineView.frame = CGRectMake(0, CGRectGetMaxY(listLabeBack.frame), self.view.frame.size.width,1);
|
||
// lineView.backgroundColor = RGB(241, 241, 241);
|
||
// [section0Header addSubview:lineView];
|
||
// //今天
|
||
// UIView *todayLabeBack =[[UIView alloc] init];
|
||
// todayLabeBack.frame = CGRectMake(0,CGRectGetMaxY(lineView.frame),self.view.frame.size.width, BACKVIEW_ROWH);
|
||
// todayLabeBack.backgroundColor = [UIColor whiteColor];
|
||
//
|
||
// [section0Header addSubview:todayLabeBack];
|
||
// UILabel *todayLabe=[[UILabel alloc] init];
|
||
// todayLabe.frame = CGRectMake(space,0,self.view.frame.size.width, BACKVIEW_ROWH);
|
||
// todayLabe.textColor =RGB(153, 153, 153);
|
||
// todayLabe.font = [UIFont systemFontOfSize:14];
|
||
// todayLabe.text = @"最近24小时";
|
||
// todayLabe.backgroundColor = [UIColor whiteColor];
|
||
// //todayLabe.text.
|
||
// [todayLabeBack addSubview:todayLabe];
|
||
//
|
||
//
|
||
//
|
||
// return section0Header;
|
||
// }
|
||
//
|
||
// return nil;
|
||
//
|
||
//}
|
||
//
|
||
//-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
|
||
// CGFloat space = 10;
|
||
//
|
||
// if (section ==1) {
|
||
// //更多
|
||
// UIView *moreLabeBack =[[UIView alloc] init];
|
||
// moreLabeBack.frame = CGRectMake(0,0,self.view.frame.size.width, BACKVIEW_ROWH);
|
||
// moreLabeBack.backgroundColor = [UIColor whiteColor];
|
||
// UILabel *moreLabe=[[UILabel alloc] init];
|
||
// moreLabe.frame = CGRectMake(space,0,self.view.frame.size.width, BACKVIEW_ROWH);
|
||
// moreLabe.textColor =RGB(153, 153, 153);
|
||
// moreLabe.font = [UIFont systemFontOfSize:14];
|
||
// moreLabe.text = @"查看更多";
|
||
// moreLabe.backgroundColor = [UIColor whiteColor];
|
||
// [moreLabeBack addSubview:moreLabe];
|
||
// moreLabe.userInteractionEnabled = YES;
|
||
// UITapGestureRecognizer *moreGesture =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(moreDataRequset)];
|
||
// [moreLabe addGestureRecognizer:moreGesture];
|
||
//
|
||
// return moreLabeBack;
|
||
//
|
||
// }
|
||
// return nil;
|
||
//}
|
||
#pragma mark - moreDataRequset
|
||
|
||
-(void)moreDataRequset{
|
||
|
||
// //today
|
||
NSDate *nowDate = [NSDate date];
|
||
NSInteger interval =31;
|
||
// //interval(1或3...)天前
|
||
NSDate *startDate = [nowDate dateByAddingTimeInterval: -(interval*24*60*60)];
|
||
//加载更多时 设置 startDate 为31 天前 可获取所有 endDate 为 今天最后一个的时间 即self.nextEndDate
|
||
if (!self.nextEndDate) {
|
||
[self.view makeToast:@"无更多数据"];
|
||
return;
|
||
}
|
||
|
||
NSDate *endDate = [Utils dateFromString:self.nextEndDate];
|
||
[[P2PClient sharedClient] getPlaybackFilesWithIdByDate:self.camera.cameraId password:self.camera.cameraPass startDate:startDate endDate:endDate];
|
||
|
||
}
|
||
|
||
#pragma mark - 视频回放准备播放的回调
|
||
-(void)P2PPlaybackReady:(NSDictionary *)info{
|
||
NSLog(@"P2PPlaybackReady");
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
[UIView transitionWithView:self.movieView duration:0.3 options:UIViewAnimationOptionCurveEaseOut
|
||
animations:^{
|
||
self.movieView.alpha = 0.3;
|
||
}
|
||
|
||
completion:^(BOOL finished){
|
||
[self.movieView setHidden:YES];
|
||
//P2PPlayingbackController *playingbackController = [[P2PPlayingbackController alloc] init];
|
||
|
||
P2PPlayingbackVC *playingbackController = [[P2PPlayingbackVC alloc] init];
|
||
[self presentViewController:playingbackController animated:YES completion:nil];
|
||
|
||
}
|
||
];
|
||
});
|
||
}
|
||
|
||
#pragma mark - 视频回放挂断的回调
|
||
-(void)P2PPlaybackReject:(NSDictionary *)info{
|
||
|
||
NSLog(@"P2PPlaybackReject");
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
[UIView transitionWithView:self.movieView duration:0.3 options:UIViewAnimationOptionCurveEaseOut
|
||
animations:^{
|
||
self.movieView.alpha = 0.3;
|
||
}
|
||
|
||
completion:^(BOOL finished){
|
||
[self.movieView setHidden:YES];
|
||
[self.view makeToast:[info objectForKey:@"rejectMsg"]];
|
||
}
|
||
];
|
||
});
|
||
}
|
||
|
||
#pragma mark -
|
||
-(BOOL)shouldAutorotate{
|
||
return YES;
|
||
}
|
||
|
||
#pragma mark 支持哪些方向
|
||
|
||
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
|
||
return UIInterfaceOrientationMaskAll;
|
||
}
|
||
|
||
#pragma mark 一开始希望的屏幕方向
|
||
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
|
||
return UIInterfaceOrientationPortrait;
|
||
}
|
||
|
||
@end
|