Skip to content

Commit

Permalink
开发下载 UIDemo 事例
Browse files Browse the repository at this point in the history
tapd: http://tapd.oa.com/NEW_IOT/prong/stories/view/1020393192870647767
Change-Id: I24624fad7fd235bf5af104f2f6099c9cb1263976
  • Loading branch information
tonychanchen committed Feb 28, 2022
1 parent 495cf58 commit bebdc20
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "res_download.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@

NS_ASSUME_NONNULL_BEGIN

@protocol TIoTDemoLocalDayCustomCellDelegate <NSObject>
- (void)downLoadResWithModel:(TIoTDemoLocalFileModel *)model;
@end


@interface TIoTDemoLocalDayCustomCell : UITableViewCell
@property (nonatomic, strong) TIoTDemoLocalFileModel *model;
@property (nonatomic, weak)id<TIoTDemoLocalDayCustomCellDelegate> delegate;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ @interface TIoTDemoLocalDayCustomCell ()
@property (nonatomic, strong) UIView *contentCustomView;
@property (nonatomic, strong) UILabel *eventTimeabel;
@property (nonatomic, strong) UILabel *eventDescribe;
@property (nonatomic, strong) UIImageView *eventThumb;
@property (nonatomic, strong) UIButton *eventThumb;
@property (nonatomic, strong) UIImageView *thumbActionImage;
@end

Expand All @@ -38,7 +38,7 @@ - (void)setupCellViews {
self.contentView.backgroundColor = [UIColor colorWithHexString:KActionSheetBackgroundColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;

self.contentCustomView = [[UILabel alloc]init];
self.contentCustomView = [[UIView alloc]init];
self.contentCustomView.backgroundColor = [UIColor whiteColor]
; [self.contentView addSubview:self.contentCustomView];
[self.contentCustomView mas_makeConstraints:^(MASConstraintMaker *make) {
Expand All @@ -65,7 +65,17 @@ - (void)setupCellViews {
make.right.equalTo(self.contentCustomView.mas_right).offset(2*kWidthPadding+100);
}];

self.eventThumb = [[UIImageView alloc]init];
self.eventThumb = [[UIButton alloc]init];
[self.eventThumb setBackgroundImage:[UIImage imageNamed:@"res_download"] forState:UIControlStateNormal];
[self.eventThumb addTarget:self action:@selector(downLoadCell) forControlEvents:UIControlEventTouchUpInside];
[self.contentCustomView addSubview:self.eventThumb];
[self.eventThumb mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.contentCustomView);
make.right.equalTo(self.contentCustomView.mas_right).offset(-kWidthPadding);
make.width.height.mas_equalTo(32);
}];

/*self.eventThumb = [[UIImageView alloc]init];
self.eventThumb.backgroundColor = [UIColor blackColor];
[self.contentCustomView addSubview:self.eventThumb];
[self.eventThumb mas_makeConstraints:^(MASConstraintMaker *make) {
Expand All @@ -81,19 +91,28 @@ - (void)setupCellViews {
[self.thumbActionImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.eventThumb);
make.width.height.mas_equalTo(32);
}];
}];*/

}

- (void)downLoadCell {
if ([self.delegate respondsToSelector:@selector(downLoadResWithModel:)]) {
[self.delegate downLoadResWithModel:_model];
}
}

- (void)setModel:(TIoTDemoLocalFileModel *)model {
_model = model;
NSString *timeString = [NSString convertTimestampToTime:model.start_time?:@"" byDateFormat:@"YYYY-MM-dd HH:mm:ss"];
/*NSString *timeString = [NSString convertTimestampToTime:model.start_time?:@"" byDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSString *dayTime = [timeString componentsSeparatedByString:@" "].lastObject;
NSString *hourString = [dayTime componentsSeparatedByString:@":"].firstObject;
NSString *minuteString = [dayTime componentsSeparatedByString:@":"][1];
self.eventTimeabel.text = [NSString stringWithFormat:@"%@:%@",hourString,minuteString];
self.eventDescribe.text = model.file_name?:@"";
[self.eventThumb setImageWithURLStr:model.file_size?:@"" placeHolder:@""];
self.eventDescribe.text = model.file_name?:@"";*/

NSString *startString = [NSString convertTimestampToTime:model.start_time?:@"" byDateFormat:@"HH:mm:ss"];
NSString *endString = [NSString convertTimestampToTime:model.end_time?:@"" byDateFormat:@"HH:mm:ss"];
self.eventTimeabel.text = [NSString stringWithFormat:@"%@ - %@",startString,endString];
}

- (void)awakeFromNib {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

static NSString *const kPlayback = @"ipc.flv?action=playback";

@interface TIoTDemoLocalRecordVC ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource, TIoTCoreXP2PBridgeDelegate>
@interface TIoTDemoLocalRecordVC ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource, TIoTCoreXP2PBridgeDelegate, TIoTDemoLocalDayCustomCellDelegate>
@property (nonatomic, assign) CGRect screenRect;
@property (nonatomic, strong) NSString *dayDateString; //选择天日期
@property (nonatomic, strong) UIImageView *imageView;
Expand Down Expand Up @@ -436,7 +436,7 @@ - (void)setupUIViews {
self.tableView.backgroundColor = [UIColor colorWithHexString:KActionSheetBackgroundColor];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.rowHeight = 84;
self.tableView.rowHeight = 66;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView registerClass:[TIoTDemoLocalDayCustomCell class] forCellReuseIdentifier:kPlaybackLocalCellID];
[self.view addSubview:self.tableView];
Expand Down Expand Up @@ -727,6 +727,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TIoTDemoLocalDayCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:kPlaybackLocalCellID forIndexPath:indexPath];
cell.delegate = self;
cell.model = self.dataArray[indexPath.row];
return cell;
}
Expand All @@ -739,28 +740,25 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
self.isPause = NO;

TIoTDemoLocalFileModel *selectedModel = self.dataArray[indexPath.row];
// [self setVieoPlayerStartPlayStartTime:selectedModel.start_time endTime:selectedModel.end_time];
[self downLoadFile:selectedModel];
[self setVieoPlayerStartPlayStartTime:selectedModel.start_time endTime:selectedModel.end_time];
// [self downLoadResWithModel:selectedModel];
}

- (void)downLoadFile:(TIoTDemoLocalFileModel *)filemodel {
// [TIoTCoreXP2PBridge sharedInstance].logEnable = NO;
#pragma mark - TIoTDemoLocalDayCustomCellDelegate
- (void)downLoadResWithModel:(TIoTDemoLocalFileModel *)model {

NSString *logFile = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:filemodel.file_name];
[TIoTCoreXP2PBridge sharedInstance].logEnable = NO;
[MBProgressHUD showLodingNoneEnabledInView:self.view withMessage:@"下载资源中"];

NSString *logFile = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:model.file_name];
[[NSFileManager defaultManager] removeItemAtPath:logFile error:nil];
[[NSFileManager defaultManager] createFileAtPath:logFile contents:nil attributes:nil];
_saveDownloadFile = [NSFileHandle fileHandleForWritingAtPath:logFile];

//设置代理,接受《下载的视频数据》和《下载完成事件》代理
[TIoTCoreXP2PBridge sharedInstance].delegate = self;

UILabel *fileTip = [[UILabel alloc] initWithFrame:self.imageView.bounds];
fileTip.text = @"数据帧写文件中...";
fileTip.textAlignment = NSTextAlignmentCenter;
fileTip.textColor = [UIColor whiteColor];
[self.imageView addSubview:fileTip];

NSString *fileurl = [NSString stringWithFormat:@"action=download&channel=0&file_name=%@&offset=%d",filemodel.file_name ,0];
NSString *fileurl = [NSString stringWithFormat:@"action=download&channel=0&file_name=%@&offset=%d",model.file_name ,0];
[[TIoTCoreXP2PBridge sharedInstance] startAvRecvService:self.deviceName?:@"" cmd:fileurl];
}

Expand All @@ -779,6 +777,7 @@ - (void)reviceEventMsgWithID:(NSString *)dev_name eventType:(XP2PType)eventType
NSLog(@"----videodataFFFFFFFFFinsi===%d",eventType);
[[TIoTCoreXP2PBridge sharedInstance] stopAvRecvService:self.deviceName?:@""];

[MBProgressHUD dismissInView:self.view];
[MBProgressHUD showError:@"文件已下载完成"];
}
}
Expand Down
2 changes: 2 additions & 0 deletions Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ extern NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd;
@protocol TIoTCoreXP2PBridgeDelegate <NSObject>

/*
* ⚠️⚠️⚠️ 谨慎!!! === 此接口切勿执行耗时操作,耗时操作请切换线程,切勿卡住当前线程
*
* 裸流接口使用方式:
* 通过 startAvRecvService 和 stopAvRecvService 接口,可以启动和停止裸流传输
* 客户端拉取到的裸流数据对应 data 参数
Expand Down

0 comments on commit bebdc20

Please sign in to comment.