aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Jordan2012-04-25 23:42:43 -0400
committerBrian Jordan2012-04-25 23:42:43 -0400
commit3c243aeaba4540732f820ec5d88c7cca3277bc5e (patch)
treea965ba6eb500b830a6ae0980310d3bc700cef7f6
parente9463eded67de701f9c3b9d0d794ca09ca913d75 (diff)
downloadVideo-Tuneup-3c243aeaba4540732f820ec5d88c7cca3277bc5e.tar.bz2
load video from library. Resolves Issue #19
-rw-r--r--Video Tuneup/Classes/AssetsViewController.h4
-rw-r--r--Video Tuneup/Classes/AssetsViewController.m20
-rw-r--r--Video Tuneup/ViewController.h3
-rw-r--r--Video Tuneup/ViewController.m62
-rw-r--r--Video Tuneup/en.lproj/ViewController_iPad.xib2
5 files changed, 61 insertions, 30 deletions
diff --git a/Video Tuneup/Classes/AssetsViewController.h b/Video Tuneup/Classes/AssetsViewController.h
index ec64d3a..96dd3df 100644
--- a/Video Tuneup/Classes/AssetsViewController.h
+++ b/Video Tuneup/Classes/AssetsViewController.h
@@ -8,12 +8,16 @@
#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>
+#import "ViewController.h"
@interface AssetsViewController : UITableViewController {
NSMutableArray *assets;
+ ViewController *_viewController;
}
@property (nonatomic, retain) UIActivityIndicatorView *activity;
@property (nonatomic, retain) ALAssetsLibrary *library;
+- (void)setParentViewController:(ViewController *)viewController;
+
@end
diff --git a/Video Tuneup/Classes/AssetsViewController.m b/Video Tuneup/Classes/AssetsViewController.m
index c948a0e..1a9e836 100644
--- a/Video Tuneup/Classes/AssetsViewController.m
+++ b/Video Tuneup/Classes/AssetsViewController.m
@@ -7,6 +7,7 @@
//
#import "AssetsViewController.h"
+#import "ViewController.h"
@implementation AssetsViewController
@@ -165,10 +166,29 @@
}
*/
+#pragma mark - Reference back to media player
+
+- (void)setParentViewController:(ViewController *)viewController {
+ _viewController = viewController;
+}
+
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
+
+ NSLog(@"Clicked on a row!!");
+ ALAsset *asset = [assets objectAtIndex:indexPath.row];
+ NSDictionary *assetURLs = [asset valueForProperty:ALAssetPropertyURLs];
+ for (NSString *assetURLKey in assetURLs) {
+ if (_viewController != nil) {
+ NSLog(@"AssetURL %@", [assetURLs valueForKey:assetURLKey]);
+ [_viewController loadAssetFromFile:[assetURLs valueForKey:assetURLKey]];
+ }
+ }
+
+ // TODO: hide this panel
+
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
diff --git a/Video Tuneup/ViewController.h b/Video Tuneup/ViewController.h
index 8409c4f..c926a8a 100644
--- a/Video Tuneup/ViewController.h
+++ b/Video Tuneup/ViewController.h
@@ -41,7 +41,8 @@
- (void)hideCameraRollText;
-- (IBAction)loadAssetFromFile:sender;
+- (IBAction)loadDefaultAssetFromFile:sender;
+- (IBAction)loadAssetFromFile:(NSURL *)fileURL;
- (IBAction)loadAudioFromFile:sender;
- (IBAction)play:sender;
- (IBAction)pause:sender;
diff --git a/Video Tuneup/ViewController.m b/Video Tuneup/ViewController.m
index da1616c..6637c9d 100644
--- a/Video Tuneup/ViewController.m
+++ b/Video Tuneup/ViewController.m
@@ -67,40 +67,45 @@ mScrubber, mediaLibraryButton, mediaLibraryPopover;
[self play:nil];
}
-- (IBAction)loadAssetFromFile:sender {
- NSLog(@"Loading asset.");
-
- NSURL *fileURL = [[NSBundle mainBundle]
- URLForResource:@"sample_iPod" withExtension:@"m4v"];
+- (void)loadAssetFromFile:(NSURL*)fileURL {
asset = [AVURLAsset URLAssetWithURL:fileURL options:nil];
- NSLog(@"Asset duration is %f", CMTimeGetSeconds([asset duration]));
-
- NSString *tracksKey = @"tracks";
+ NSLog(@"Asset duration is %f", CMTimeGetSeconds([asset duration]));
- [asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler:
- ^{
- NSLog(@"Handler block reached");
- // Completion handler block.
- dispatch_async(dispatch_get_main_queue(),
- ^{
- NSError *error = nil;
- AVKeyValueStatus status = [asset statusOfValueForKey:tracksKey error:&error];
+ NSString *tracksKey = @"tracks";
- if (status == AVKeyValueStatusLoaded) {
- [self refreshEditor];
+ [asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler:
+ ^{
+ NSLog(@"Handler block reached");
+ // Completion handler block.
+ dispatch_async(dispatch_get_main_queue(),
+ ^{
+ NSError *error = nil;
+ AVKeyValueStatus status = [asset statusOfValueForKey:tracksKey error:&error];
+
+ if (status == AVKeyValueStatusLoaded) {
+ [self refreshEditor];
+
+ // File has loaded into player
+ NSLog(@"File loaded!");
+ NSLog(@"Asset duration is %f", CMTimeGetSeconds([asset duration]));
+
+ }
+ else {
+ // You should deal with the error appropriately.
+ NSLog(@"The asset's tracks were not loaded:\n%@", [error localizedDescription]);
+ }
+ });
+ }];
+}
+
+- (IBAction)loadDefaultAssetFromFile:sender {
+ NSLog(@"Loading asset.");
- // File has loaded into player
- NSLog(@"File loaded!");
- NSLog(@"Asset duration is %f", CMTimeGetSeconds([asset duration]));
+ NSURL *fileURL = [[NSBundle mainBundle]
+ URLForResource:@"sample_iPod" withExtension:@"m4v"];
- }
- else {
- // You should deal with the error appropriately.
- NSLog(@"The asset's tracks were not loaded:\n%@", [error localizedDescription]);
- }
- });
- }];
+ [self loadAssetFromFile:fileURL];
}
- (IBAction)loadAudioFromFile:(id)sender {
@@ -441,6 +446,7 @@ mScrubber, mediaLibraryButton, mediaLibraryPopover;
UIButton *theButton = (UIButton *)sender;
AssetsViewController *avc = [[AssetsViewController alloc] initWithStyle:UITableViewStylePlain];
+ [avc setParentViewController:self];
mediaLibraryPopover = [[UIPopoverController alloc] initWithContentViewController:avc];
// [mediaLibraryPopover setPopoverContentSize:<#(CGSize)#>// Change size of popover so that it doesn't take up the whole height
diff --git a/Video Tuneup/en.lproj/ViewController_iPad.xib b/Video Tuneup/en.lproj/ViewController_iPad.xib
index 94aaab0..5fe78b7 100644
--- a/Video Tuneup/en.lproj/ViewController_iPad.xib
+++ b/Video Tuneup/en.lproj/ViewController_iPad.xib
@@ -372,7 +372,7 @@
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
- <string key="label">loadAssetFromFile:</string>
+ <string key="label">loadDefaultAssetFromFile:</string>
<reference key="source" ref="1049445720"/>
<reference key="destination" ref="841351856"/>
<int key="IBEventType">7</int>