1 #import "LibraryViewController.h"
2 #import "VideoViewController.h"
3 #import <AssetsLibrary/AssetsLibrary.h>
5 @interface LibraryViewController ()
9 @implementation LibraryViewController
14 [super setTitle:@"Library"];
15 [self refreshMediaItems];
18 - (IBAction)refresh:(id)sender
20 [self refreshMediaItems];
21 [self.tableView reloadData];
24 static NSString *CellIdentifier = @"CellIdentifier";
26 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
30 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
34 case 0: return @"Photo library";
35 case 1: return @"iTunes file sharing";
36 default: return @"Online files";
40 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
43 return [self->libraryEntries count];
45 return [self->mediaEntries count];
47 return [self->onlineEntries count];
53 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
54 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
56 UILabel *title = (UILabel *)[cell.contentView viewWithTag:10];
57 UILabel *subtitle = (UILabel *)[cell.contentView viewWithTag:11];
59 switch (indexPath.section) {
60 case 0: subtitle.text = [self->libraryEntries objectAtIndex:indexPath.item];
62 case 1: subtitle.text = [self->mediaEntries objectAtIndex:indexPath.item];
64 case 2: subtitle.text = [self->onlineEntries objectAtIndex:indexPath.item];
70 NSArray *components = [subtitle.text pathComponents];
71 title.text = components.lastObject;
76 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
80 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
84 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
85 if ([segue.identifier isEqualToString:@"playVideo"]) {
86 NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
87 VideoViewController *destViewController = segue.destinationViewController;
88 UITableViewCell *cell = [[self tableView] cellForRowAtIndexPath:indexPath];
89 UILabel *label = (UILabel *)[cell.contentView viewWithTag:10];
90 destViewController.title = label.text;
91 label = (UILabel *)[cell.contentView viewWithTag:11];
92 destViewController.uri = label.text;
96 - (void)refreshMediaItems {
97 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSAllDomainsMask, YES);
98 NSString *docsPath = [paths objectAtIndex:0];
100 /* Entries from the Photo Library */
101 NSMutableArray *entries = [[NSMutableArray alloc] init];
102 ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
103 [library enumerateGroupsWithTypes:ALAssetsGroupAll
104 usingBlock:^(ALAssetsGroup *group, BOOL *stop)
107 [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
110 [entries addObject:[NSString stringWithFormat:@"%@",[result valueForProperty:ALAssetPropertyAssetURL]]];
116 [self.tableView reloadData];
119 failureBlock:^(NSError *error)
124 self->libraryEntries = entries;
126 /* Retrieve entries from iTunes file sharing */
127 entries = [[NSMutableArray alloc] init];
128 for (NSString *e in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docsPath error:nil])
130 [entries addObject:[NSString stringWithFormat:@"file://%@/%@", docsPath, e]];
132 self->mediaEntries = entries;
134 /* Hardcoded list of Online media files */
135 entries = [[NSMutableArray alloc] init];
138 [entries addObject:@"http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi"];
139 [entries addObject:@"http://mirrorblender.top-ix.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_h264.mov"];
140 [entries addObject:@"http://mirrorblender.top-ix.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_stereo.ogg"];
141 [entries addObject:@"http://mirrorblender.top-ix.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_stereo.avi"];
144 // The ftp.nluug.nl links no longer work
145 // [entries addObject:@"http://ftp.nluug.nl/ftp/graphics/blender/apricot/trailer/Sintel_Trailer1.480p.DivX_Plus_HD.mkv"];
146 // [entries addObject:@"http://ftp.nluug.nl/ftp/graphics/blender/apricot/trailer/sintel_trailer-480p.mp4"];
147 // [entries addObject:@"http://ftp.nluug.nl/ftp/graphics/blender/apricot/trailer/sintel_trailer-480p.ogv"];
148 [entries addObject:@"http://mirrorblender.top-ix.org/movies/sintel-1024-surround.mp4"];
151 [entries addObject:@"http://blender-mirror.kino3d.org/mango/download.blender.org/demo/movies/ToS/tears_of_steel_720p.mkv"];
152 [entries addObject:@"http://blender-mirror.kino3d.org/mango/download.blender.org/demo/movies/ToS/tears_of_steel_720p.mov"];
153 [entries addObject:@"http://media.xiph.org/mango/tears_of_steel_1080p.webm"];
156 [entries addObject:@"http://radio.hbr1.com:19800/trance.ogg"];
157 [entries addObject:@"http://radio.hbr1.com:19800/tronic.aac"];
159 // Non-existing entries (to debug error reporting facilities)
160 [entries addObject:@"http://non-existing.org/Non_Existing_Server"];
161 [entries addObject:@"https://www.freedesktop.org/software/gstreamer-sdk/data/media/Non_Existing_File"];
163 self->onlineEntries = entries;