-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoViewController.m
107 lines (95 loc) · 4.04 KB
/
VideoViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// VideoViewController.m
// HymnLens
//
// Created by 陈志浩 on 16/1/28.
// Copyright © 2016年 陈志浩. All rights reserved.
//
#import "VideoViewController.h"
#import "HLMediaController.h"
#import "videoListV.h"
#import "videoV.h"
@interface VideoViewController ()
@property (nonatomic, strong) NSMutableArray * videoList;
@property (nonatomic, strong) NSDictionary * videoInfo;
@property (nonatomic, strong) videoListV * mainV;
@end
@implementation VideoViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
for (UIView * subview in self.view.subviews){
[subview removeFromSuperview];
}
[self loadVideoInfo];
[self loadMainView];
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
NSInteger line = _mainV.count / 3;
_mainV.contentSize = CGSizeMake(0, 7 * (line + 1) + (SCREEN_WIDTH - 28) / 3 * line);
NSLog(@"Done");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)loadVideoInfo{
NSArray * pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * path = [pathArr objectAtIndex:0];
NSString * filePath = [path stringByAppendingString:@"/videoInfo.plist"];
NSString * thumbnailPath = [path stringByAppendingString:@"/Videos/01.jpeg"];
NSString * videoPath = [path stringByAppendingString:@"/Videos/01.mp4"];
NSDictionary * videoInfo = [NSDictionary dictionaryWithObjectsAndKeys:thumbnailPath, @"thumbnailPath", videoPath, @"videoPath", nil];
NSArray * videoList = [NSArray arrayWithObject:videoInfo];
[videoList writeToFile:filePath atomically:YES];
}
- (void)loadMainView{
_mainV = [[videoListV alloc]init];
[self.view addSubview:_mainV];
[_mainV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top);
make.bottom.equalTo(self.view.mas_bottom);
make.left.equalTo(self.view.mas_left);
make.right.equalTo(self.view.mas_right);
}];
NSArray * pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * path = [pathArr objectAtIndex:0];
NSString * filePath = [path stringByAppendingString:@"/videoInfo.plist"];
self.videoList = [NSMutableArray arrayWithContentsOfFile:filePath];
_mainV.count = self.videoList.count;
NSInteger cnt = 0;
for (videoV * subVideoV in _mainV.videoArr){
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(displayVideo:)];
tap.delegate = self;
tap.numberOfTouchesRequired = 1;
[subVideoV addGestureRecognizer:tap];
// subVideoV.thumbnailV.image = [UIImage imageNamed:@"06.jpeg"];
self.videoInfo = [self.videoList objectAtIndex:cnt];
NSString * thumbnailPath = [self.videoInfo objectForKey:@"thumbnailPath"];
UIImage * image = [UIImage imageWithContentsOfFile:thumbnailPath];
subVideoV.thumbnailV.image = image;
cnt++;
}
}
- (void)displayVideo:(UITapGestureRecognizer *)tap{
self.videoInfo = [self.videoList objectAtIndex:tap.view.tag];
NSString * videoPath = [self.videoInfo objectForKey:@"videoPath"];
HLMediaController * videoPlayer = [[HLMediaController alloc]initWithVideoPath:videoPath];
[self.navigationController pushViewController:videoPlayer animated:YES];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return 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.
}
*/
@end