Add Photo Library items to iOS Tutorial 5

This commit is contained in:
Xavi Artigas 2013-05-22 12:51:05 +02:00
parent 1db12234ad
commit 72b7f3f2a2
3 changed files with 52 additions and 11 deletions

View file

@ -2,6 +2,7 @@
@interface LibraryViewController : UITableViewController @interface LibraryViewController : UITableViewController
{ {
NSArray *libraryEntries;
NSArray *mediaEntries; NSArray *mediaEntries;
NSArray *onlineEntries; NSArray *onlineEntries;
} }

View file

@ -1,5 +1,6 @@
#import "LibraryViewController.h" #import "LibraryViewController.h"
#import "VideoViewController.h" #import "VideoViewController.h"
#import <AssetsLibrary/AssetsLibrary.h>
@interface LibraryViewController () @interface LibraryViewController ()
@ -23,14 +24,15 @@
static NSString *CellIdentifier = @"CellIdentifier"; static NSString *CellIdentifier = @"CellIdentifier";
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2; return 3;
} }
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{ {
switch (section) switch (section)
{ {
case 0: return @"Local files (iTunes file sharing)"; case 0: return @"Photo library";
case 1: return @"iTunes file sharing";
default: return @"Online files"; default: return @"Online files";
} }
} }
@ -38,8 +40,10 @@ static NSString *CellIdentifier = @"CellIdentifier";
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (section) { switch (section) {
case 0: case 0:
return [self->mediaEntries count]; return [self->libraryEntries count];
case 1: case 1:
return [self->mediaEntries count];
case 2:
return [self->onlineEntries count]; return [self->onlineEntries count];
default: default:
return 0; return 0;
@ -52,13 +56,15 @@ static NSString *CellIdentifier = @"CellIdentifier";
UILabel *title = (UILabel *)[cell.contentView viewWithTag:10]; UILabel *title = (UILabel *)[cell.contentView viewWithTag:10];
UILabel *subtitle = (UILabel *)[cell.contentView viewWithTag:11]; UILabel *subtitle = (UILabel *)[cell.contentView viewWithTag:11];
if(indexPath.section == 0) switch (indexPath.section) {
{ case 0: subtitle.text = [self->libraryEntries objectAtIndex:indexPath.item];
subtitle.text = [NSString stringWithFormat:@"file://%@", break;
[self->mediaEntries objectAtIndex:indexPath.item], nil]; case 1: subtitle.text = [self->mediaEntries objectAtIndex:indexPath.item];
} else if (indexPath.section == 1) break;
{ case 2: subtitle.text = [self->onlineEntries objectAtIndex:indexPath.item];
subtitle.text = [self->onlineEntries objectAtIndex:indexPath.item]; break;
default:
break;
} }
NSArray *components = [subtitle.text pathComponents]; NSArray *components = [subtitle.text pathComponents];
@ -91,13 +97,41 @@ static NSString *CellIdentifier = @"CellIdentifier";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSAllDomainsMask, YES); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSAllDomainsMask, YES);
NSString *docsPath = [paths objectAtIndex:0]; NSString *docsPath = [paths objectAtIndex:0];
/* Entries from the Photo Library */
NSMutableArray *entries = [[NSMutableArray alloc] init]; NSMutableArray *entries = [[NSMutableArray alloc] init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
if (group) {
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
{
if(result) {
[entries addObject:[NSString stringWithFormat:@"%@",[result valueForProperty:ALAssetPropertyAssetURL]]];
*stop = NO;
}
}];
} else {
[self.tableView reloadData];
}
}
failureBlock:^(NSError *error)
{
NSLog(@"ERROR");
}
];
self->libraryEntries = entries;
/* Retrieve entries from iTunes file sharing */
entries = [[NSMutableArray alloc] init];
for (NSString *e in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docsPath error:nil]) for (NSString *e in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docsPath error:nil])
{ {
[entries addObject:[NSString stringWithFormat:@"%@/%@",docsPath, e]]; [entries addObject:[NSString stringWithFormat:@"file://%@/%@", docsPath, e]];
} }
self->mediaEntries = entries; self->mediaEntries = entries;
/* Hardcoded list of Online media files */
entries = [[NSMutableArray alloc] init]; entries = [[NSMutableArray alloc] init];
// Big Buck Bunny // Big Buck Bunny

View file

@ -138,6 +138,9 @@ GST_PLUGIN_STATIC_DECLARE(eglglessink);
#if defined(GST_IOS_PLUGIN_APPLEMEDIA_NONPUBLIC) || defined(GST_IOS_PLUGINS_SYS) #if defined(GST_IOS_PLUGIN_APPLEMEDIA_NONPUBLIC) || defined(GST_IOS_PLUGINS_SYS)
GST_PLUGIN_STATIC_DECLARE(applemedia_nonpublic); GST_PLUGIN_STATIC_DECLARE(applemedia_nonpublic);
#endif #endif
#if defined(GST_IOS_PLUGIN_APPLEMEDIA) || defined(GST_IOS_PLUGINS_SYS)
GST_PLUGIN_STATIC_DECLARE(applemedia);
#endif
#if defined(GST_IOS_PLUGIN_LIBVISUAL) || defined(GST_IOS_PLUGINS_VIS) #if defined(GST_IOS_PLUGIN_LIBVISUAL) || defined(GST_IOS_PLUGINS_VIS)
GST_PLUGIN_STATIC_DECLARE(libvisual); GST_PLUGIN_STATIC_DECLARE(libvisual);
#endif #endif
@ -639,6 +642,9 @@ gst_ios_init (void)
#if defined(GST_IOS_PLUGIN_APPLEMEDIA_NONPUBLIC) || defined(GST_IOS_PLUGINS_SYS) #if defined(GST_IOS_PLUGIN_APPLEMEDIA_NONPUBLIC) || defined(GST_IOS_PLUGINS_SYS)
GST_PLUGIN_STATIC_REGISTER(applemedia_nonpublic); GST_PLUGIN_STATIC_REGISTER(applemedia_nonpublic);
#endif #endif
#if defined(GST_IOS_PLUGIN_APPLEMEDIA) || defined(GST_IOS_PLUGINS_SYS)
GST_PLUGIN_STATIC_REGISTER(applemedia);
#endif
#if defined(GST_IOS_PLUGIN_LIBVISUAL) || defined(GST_IOS_PLUGINS_VIS) #if defined(GST_IOS_PLUGIN_LIBVISUAL) || defined(GST_IOS_PLUGINS_VIS)
GST_PLUGIN_STATIC_REGISTER(libvisual); GST_PLUGIN_STATIC_REGISTER(libvisual);
#endif #endif