aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2012-04-24 19:08:20 -0400
committerTeddy Wing2012-04-24 19:08:20 -0400
commit97c2c473234e9fced138a09aec80a416f0400c04 (patch)
treea24c0143c9efa6ffa05dfebfdfab003ed1ab25ca
parent3fc6511769e473f09f17956f23c307d43b613728 (diff)
downloadVideo-Tuneup-97c2c473234e9fced138a09aec80a416f0400c04.tar.bz2
Video library popover works.
-rw-r--r--Video Tuneup/Classes/AssetsViewController.h8
-rw-r--r--Video Tuneup/Classes/AssetsViewController.m37
-rw-r--r--Video Tuneup/ViewController.m20
3 files changed, 43 insertions, 22 deletions
diff --git a/Video Tuneup/Classes/AssetsViewController.h b/Video Tuneup/Classes/AssetsViewController.h
index 6b13ae7..ec64d3a 100644
--- a/Video Tuneup/Classes/AssetsViewController.h
+++ b/Video Tuneup/Classes/AssetsViewController.h
@@ -7,7 +7,13 @@
//
#import <UIKit/UIKit.h>
+#import <AssetsLibrary/AssetsLibrary.h>
-@interface AssetsViewController : UITableViewController
+@interface AssetsViewController : UITableViewController {
+ NSMutableArray *assets;
+}
+
+@property (nonatomic, retain) UIActivityIndicatorView *activity;
+@property (nonatomic, retain) ALAssetsLibrary *library;
@end
diff --git a/Video Tuneup/Classes/AssetsViewController.m b/Video Tuneup/Classes/AssetsViewController.m
index b3df331..c948a0e 100644
--- a/Video Tuneup/Classes/AssetsViewController.m
+++ b/Video Tuneup/Classes/AssetsViewController.m
@@ -10,6 +10,8 @@
@implementation AssetsViewController
+@synthesize activity, library;
+
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
@@ -32,6 +34,29 @@
- (void)viewDidLoad
{
[super viewDidLoad];
+
+ void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
+ if(result != NULL) {
+ NSLog(@"See Asset: %@", result);
+ [assets addObject:result];
+ }
+ };
+ void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) {
+ if(group != nil) {
+ [group setAssetsFilter:[ALAssetsFilter allVideos]];
+ [group enumerateAssetsUsingBlock:assetEnumerator];
+ }
+ [self.tableView reloadData];
+ [self.activity stopAnimating];
+ [self.activity setHidden:YES];
+ };
+ assets = [[NSMutableArray alloc] init];
+ library = [[ALAssetsLibrary alloc] init];
+ [library enumerateGroupsWithTypes:ALAssetsGroupAll
+ usingBlock:assetGroupEnumerator
+ failureBlock: ^(NSError *error) {
+ NSLog(@"Failure");
+ }];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
@@ -77,16 +102,12 @@
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
-#warning Potentially incomplete method implementation.
- // Return the number of sections.
- return 0;
+ return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
-#warning Incomplete method implementation.
- // Return the number of rows in the section.
- return 0;
+ return [assets count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
@@ -98,7 +119,9 @@
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
- // Configure the cell...
+ ALAsset *asset = [assets objectAtIndex:indexPath.row];
+ [cell.imageView setImage:[UIImage imageWithCGImage:[asset thumbnail]]];
+ [cell.textLabel setText:[NSString stringWithFormat:@"Test %d", indexPath.row+1]];
return cell;
}
diff --git a/Video Tuneup/ViewController.m b/Video Tuneup/ViewController.m
index 972bcce..3bc41a2 100644
--- a/Video Tuneup/ViewController.m
+++ b/Video Tuneup/ViewController.m
@@ -9,6 +9,7 @@
#import "ViewController.h"
#import "PlayerView.h"
#import "SimpleEditor.h"
+#import "AssetsViewController.h"
// Define this constant for the key-value observation context.
static const NSString *ItemStatusContext;
@@ -404,24 +405,15 @@ mScrubber, mediaLibraryButton, mediaLibraryPopover;
// http://stackoverflow.com/questions/2469523/mpmediapickercontroller-for-selecting-video-files#answer-3212470
UIButton *theButton = (UIButton *)sender;
- UIImagePickerController* picker = [[UIImagePickerController alloc] init];
- picker.delegate = self;
- picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
- picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
- mediaLibraryPopover = [[UIPopoverController alloc] initWithContentViewController:picker];
+
+ AssetsViewController *avc = [[AssetsViewController alloc] initWithStyle:UITableViewStylePlain];
+
+ mediaLibraryPopover = [[UIPopoverController alloc] initWithContentViewController:avc];
+// [mediaLibraryPopover setPopoverContentSize:<#(CGSize)#>// Change size of popover so that it doesn't take up the whole height
[self.mediaLibraryPopover presentPopoverFromRect:[theButton bounds] inView:theButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
-- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
- [mediaLibraryPopover dismissPopoverAnimated:YES];
-
- NSLog(@"MEDIA URL:");
- NSLog(@"%@", [info objectForKey:UIImagePickerControllerMediaURL]);
- NSLog(@"MEDIA REFERENCE URL:");
- NSLog(@"%@", [info objectForKey:UIImagePickerControllerReferenceURL]);
-}
-
#pragma mark - View controller boilerplate
- (void)didReceiveMemoryWarning {