Split out documentation into subfolders.
[platform/upstream/gstreamer.git] / examples / tutorials / xcode iOS / Tutorial 5 / LibraryViewController.m
1 #import "LibraryViewController.h"
2 #import "VideoViewController.h"
3 #import <AssetsLibrary/AssetsLibrary.h>
4
5 @interface LibraryViewController ()
6
7 @end
8
9 @implementation LibraryViewController
10
11 - (void)viewDidLoad
12 {
13     [super viewDidLoad];
14     [super setTitle:@"Library"];
15     [self refreshMediaItems];
16 }
17
18 - (IBAction)refresh:(id)sender
19 {
20     [self refreshMediaItems];
21     [self.tableView reloadData];
22 }
23
24 static NSString *CellIdentifier = @"CellIdentifier";
25
26 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
27     return 3;
28 }
29
30 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
31 {
32     switch (section)
33     {
34         case 0: return @"Photo library";
35         case 1: return @"iTunes file sharing";
36         default: return @"Online files";
37     }
38 }
39
40 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
41     switch (section) {
42         case 0:
43             return [self->libraryEntries count];
44         case 1:
45             return [self->mediaEntries count];
46         case 2:
47             return [self->onlineEntries count];
48         default:
49             return 0;
50     }
51 }
52
53 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
54     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
55     // Configure Cell
56     UILabel *title = (UILabel *)[cell.contentView viewWithTag:10];
57     UILabel *subtitle = (UILabel *)[cell.contentView viewWithTag:11];
58
59     switch (indexPath.section) {
60         case 0: subtitle.text = [self->libraryEntries objectAtIndex:indexPath.item];
61             break;
62         case 1: subtitle.text = [self->mediaEntries objectAtIndex:indexPath.item];
63             break;
64         case 2: subtitle.text = [self->onlineEntries objectAtIndex:indexPath.item];
65             break;
66         default:
67             break;
68     }
69
70     NSArray *components = [subtitle.text pathComponents];
71     title.text = components.lastObject;
72
73     return cell;
74 }
75
76 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
77     return NO;
78 }
79
80 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
81     return NO;
82 }
83
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;
93     }
94 }
95
96 - (void)refreshMediaItems {
97     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSAllDomainsMask, YES);
98     NSString *docsPath = [paths objectAtIndex:0];
99
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)
105         {
106             if (group) {
107                 [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
108                 {
109                     if(result) {
110                         [entries addObject:[NSString stringWithFormat:@"%@",[result valueForProperty:ALAssetPropertyAssetURL]]];
111                         *stop = NO;
112
113                     }
114                 }];
115             } else {
116                 [self.tableView reloadData];
117             }
118         }
119         failureBlock:^(NSError *error)
120         {
121             NSLog(@"ERROR");
122         }
123      ];
124     self->libraryEntries = entries;
125
126     /* Retrieve entries from iTunes file sharing */
127     entries = [[NSMutableArray alloc] init];
128     for (NSString *e in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docsPath error:nil])
129     {
130         [entries addObject:[NSString stringWithFormat:@"file://%@/%@", docsPath, e]];
131     }
132     self->mediaEntries = entries;
133
134     /* Hardcoded list of Online media files */
135     entries = [[NSMutableArray alloc] init];
136
137     // Big Buck Bunny
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"];
142
143     // Sintel
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"];
149
150     // Tears of Steel
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"];
154
155     // Radio stations
156     [entries addObject:@"http://radio.hbr1.com:19800/trance.ogg"];
157     [entries addObject:@"http://radio.hbr1.com:19800/tronic.aac"];
158
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"];
162
163     self->onlineEntries = entries;
164 }
165
166 @end