forked from chrisballinger/Cop-Recorder-iOS
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLecturePlayerViewController.m
More file actions
290 lines (228 loc) · 8.08 KB
/
LecturePlayerViewController.m
File metadata and controls
290 lines (228 loc) · 8.08 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
//
// LecturePlayerViewController.m
// LectureLeaks
//
// Created by Christopher Ballinger on 6/9/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "LecturePlayerViewController.h"
#import "ASIFormDataRequest.h"
@implementation LecturePlayerViewController
@synthesize submitLabel;
@synthesize durationLabel;
@synthesize currentTimeLabel;
@synthesize locationSwitch;
@synthesize progressView;
@synthesize privateDescriptionTextField;
@synthesize publicDescriptionTextField;
@synthesize nameTextField;
@synthesize recording;
@synthesize playerUpdateTimer;
@synthesize playerSlider;
@synthesize playButton;
@synthesize stopButton;
@synthesize submitButton;
@synthesize player;
@synthesize emailTextField;
@synthesize fieldsScrollView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
nameTextField.text = recording.name;
privateDescriptionTextField.text = recording.privateDescription;
publicDescriptionTextField.text = recording.publicDescription;
NSURL *url = recording.url;
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
submitButton.enabled = YES;
isPlaying = NO;
playerUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self
selector:@selector(updateElapsedTime:) userInfo:nil repeats:YES];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
self.title = [recording.date description];
if(recording.isSubmitted)
{
submitLabel.text = @"Previously Submitted";
submitLabel.textColor = [UIColor greenColor];
}
CGSize cSize = CGSizeMake(320, 253);
[fieldsScrollView setContentSize:cSize];
emailTextField.tag = 1;
[emailTextField setKeyboardType:UIKeyboardTypeEmailAddress];
}
- (void)playerItemDidReachEnd:(NSNotification *)notification {
[self stopPressed:nil];
}
-(void)viewDidDisappear:(BOOL)animated
{
[player pause];
[playerUpdateTimer invalidate];
}
- (void)viewDidUnload
{
[self setDurationLabel:nil];
[self setCurrentTimeLabel:nil];
[self setPlayerSlider:nil];
[self setPlayButton:nil];
[self setStopButton:nil];
[self setSubmitButton:nil];
[self setNameTextField:nil];
[self setPublicDescriptionTextField:nil];
[self setPrivateDescriptionTextField:nil];
[self setProgressView:nil];
[self setSubmitLabel:nil];
[self setLocationSwitch:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
// Update the call timer once a second.
- (void) updateElapsedTime:(NSTimer *) timer
{
int currentTime = player.currentTime;
duration = player.duration;
[self updateLabel:currentTimeLabel withTime:currentTime];
[self updateLabel:durationLabel withTime:duration];
if(duration != 0)
{
self.playerSlider.value = currentTime / ((float)duration);
}
if(!isPlaying)
{
playButton.title = @"Play";
playButton.enabled = YES;
}
}
-(void) updateLabel:(UILabel*)label withTime:(NSTimeInterval)time
{
int hour, minute, second;
hour = time / 3600;
minute = (time - hour * 3600) / 60;
second = (time - hour * 3600 - minute * 60);
label.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hour, minute, second];
}
- (IBAction)seek:(id)sender
{
float currentTime = self.playerSlider.value * duration;
[player setCurrentTime:currentTime];
[self updateElapsedTime:nil];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1)
{
if(!locationSwitch.on)
recording.location = @"";
[recording submitRecordingWithDelegate:self];
submitLabel.text = @"Submitting...";
submitLabel.textColor = [UIColor whiteColor];
}
}
- (IBAction)submitPressed:(id)sender
{
/*
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Submit to OpenWatch" message:@"Would you like to submit your recording to www.openwatch.net?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:nil];
[alert addButtonWithTitle:@"Yes"];
[alert show];
*/
ACLUConfirmUpload * confirmUpload = [[ACLUConfirmUpload alloc] init];
confirmUpload.delegate = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:confirmUpload];
[self.navigationController presentModalViewController:navController animated:YES];
}
-(void)uploadPressed
{
if(!locationSwitch.on)
recording.location = @"";
[recording submitRecordingWithDelegate:self];
submitLabel.text = @"Submitting...";
submitLabel.textColor = [UIColor whiteColor];
}
- (IBAction)playPressed:(id)sender
{
if(!isPlaying)
{
[player play];
playButton.title = @"Pause";
stopButton.enabled = YES;
isPlaying = YES;
}
else
{
[player pause];
playButton.title = @"Play";
isPlaying = NO;
}
}
- (IBAction)stopPressed:(id)sender
{
[player pause];
[player setCurrentTime:0];
[self updateElapsedTime:nil];
stopButton.enabled = NO;
playButton.title = @"Play";
isPlaying = NO;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField.tag == 1)
{
CGPoint bottomOffset = CGPointMake(0, fieldsScrollView.contentSize.height - self.fieldsScrollView.bounds.size.height);
[fieldsScrollView setContentOffset:bottomOffset animated:YES];
}
else {
[self.fieldsScrollView setContentOffset:CGPointZero animated:YES];
}
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if(textField.tag == 1)
{
[self.fieldsScrollView setContentOffset:CGPointZero animated:YES];
}
[textField resignFirstResponder];
recording.name = [nameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString * email = [emailTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if(![email isEqualToString:@""])
{
recording.privateDescription = [NSString stringWithFormat:@"%@ [%@]", [privateDescriptionTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]],email];
}
else {
recording.privateDescription = [privateDescriptionTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
}
recording.publicDescription = [publicDescriptionTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
[recording saveMetadata];
return YES;
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload Complete" message:@"The recording was uploaded successfully to www.openwatch.net" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
// Set TRUE if file was sent properly
recording.isSubmitted = YES;
[recording saveMetadata];
submitLabel.text = @"Submission Successful";
submitLabel.textColor = [UIColor greenColor];
progressView.hidden = TRUE;
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload Error" message:@"Upload failed, please check your internet connection and try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
submitLabel.text = @"Submission failed!";
submitLabel.textColor = [UIColor redColor];
progressView.hidden = TRUE;
}
@end