aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2012-04-26 01:55:31 -0400
committerTeddy Wing2012-04-26 01:55:31 -0400
commit03668582bcd90409def595ea6f4c463e29557664 (patch)
tree96a828ad33d9718f78b8295810696d0fb54e29d0
parent33d773e817a33eed4a282ed974700222dce42074 (diff)
parent541a72c7fda508ec21e1adf8da66043807687222 (diff)
downloadVideo-Tuneup-03668582bcd90409def595ea6f4c463e29557664.tar.bz2
Merge branch 'master' of github.com:bcjordan/Video-Tuneup
-rw-r--r--Video Tuneup/Classes/AssetsViewController.h4
-rw-r--r--Video Tuneup/Classes/AssetsViewController.m20
-rw-r--r--Video Tuneup/ViewController.h6
-rw-r--r--Video Tuneup/ViewController.m83
-rw-r--r--Video Tuneup/en.lproj/ViewController_iPad.xib4
5 files changed, 77 insertions, 40 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 6b17a9e..c9ae6a4 100644
--- a/Video Tuneup/ViewController.h
+++ b/Video Tuneup/ViewController.h
@@ -43,8 +43,10 @@
- (void)hideCameraRollText;
-- (IBAction)loadAssetFromFile:sender;
-- (IBAction)loadAudioFromFile:sender;
+- (IBAction)loadDefaultAssetFromFile:sender;
+- (IBAction)loadAssetFromFile:(NSURL *)fileURL;
+- (IBAction)loadAudioFromFile:(NSURL *)songFileURL;
+- (IBAction)loadDefaultAudioFromFile:sender;
- (IBAction)play:sender;
- (IBAction)pause:sender;
- (IBAction)rewind:sender;
diff --git a/Video Tuneup/ViewController.m b/Video Tuneup/ViewController.m
index efe3686..ec31aa6 100644
--- a/Video Tuneup/ViewController.m
+++ b/Video Tuneup/ViewController.m
@@ -71,45 +71,54 @@ 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]));
+ NSLog(@"Asset duration is %f", CMTimeGetSeconds([asset duration]));
- NSString *tracksKey = @"tracks";
+ NSString *tracksKey = @"tracks";
- [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];
+ [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 {
+- (IBAction)loadDefaultAudioFromFile:(id)sender {
NSURL *songFileURL = [[NSBundle mainBundle]
URLForResource:@"song" withExtension:@"mp3"];
+ [self loadAudioFromFile:songFileURL];
+}
+
+- (IBAction)loadAudioFromFile:(NSURL *)songFileURL {
songAsset = [AVURLAsset URLAssetWithURL:songFileURL options:nil];
NSLog(@"Song asset duration is %f", CMTimeGetSeconds([songAsset duration]));
@@ -117,6 +126,9 @@ mScrubber, mediaLibraryButton, mediaLibraryPopover;
[self refreshEditor];
}
+#pragma mark -
+#pragma mark Audio picker
+
- (IBAction)showMediaPicker:(id)sender
{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
@@ -133,13 +145,11 @@ mScrubber, mediaLibraryButton, mediaLibraryPopover;
if (mediaItemCollection) {
NSLog(@"Got media item");
-// [musicPlayer setQueueWithItemCollection: mediaItemCollection];
-// [musicPlayer play];
- NSLog(@"%@",[[[mediaItemCollection items] objectAtIndex:0]valueForKey:MPMediaItemPropertyTitle]);
-
- NSURL *url = [[[mediaItemCollection items] objectAtIndex:0] valueForProperty:MPMediaItemPropertyAssetURL];
-
- NSLog(@"%@", url);
+// NSLog(@"%@",[[[mediaItemCollection items] objectAtIndex:0]valueForKey:MPMediaItemPropertyTitle]);
+// NSURL *url = [[[mediaItemCollection items] objectAtIndex:0] valueForProperty:MPMediaItemPropertyAssetURL];
+// NSLog(@"%@", url);
+
+ [self loadAudioFromFile:url];
} else {NSLog(@"Didn't get media item!");}
@@ -445,6 +455,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 9925af3..346f2e0 100644
--- a/Video Tuneup/en.lproj/ViewController_iPad.xib
+++ b/Video Tuneup/en.lproj/ViewController_iPad.xib
@@ -402,7 +402,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>
@@ -411,7 +411,7 @@
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
- <string key="label">loadAudioFromFile:</string>
+ <string key="label">loadDefaultAudioFromFile:</string>
<reference key="source" ref="761978491"/>
<reference key="destination" ref="841351856"/>
<int key="IBEventType">7</int>