View RailsCasts Videos on Apple tvOS

Romi Susai

45 sec read

This week I tried learning Apple tvOS and thought I would consume the famous RailsCasts videos on it. I kept the source code at GitHub for you to try and plat with it https://github.com/spritlesoftware/railscasts-on-appletv.
Apple Tv Rails casts video screenshot
Gif view of apple tv with rails casts video
The key code-piece that fetches data from RailsCasts videos is:

#define FEED_URL @"http://nicoli.moddo.spritle.com/tvos/json/rails_cast.json"
@implementation RestHandler
..
...
.....
.......
for (NSDictionary *resultDict in results) {
    // Fetch data from json
    Movie *movie = [Movie new];
    movie.title = [resultDict objectForKey:@"title"];
    movie.imageURL = [resultDict objectForKey:@"preview_image"];
    movie.videoURL=[resultDict objectForKey:@"video_url"];
    [returnArray addObject:movie];
}
success(returnArray);

and the key code-piece that displays the content on Apple TV is:

#pragma mark - UICollectionView
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
   CGFloat height = (CGRectGetHeight(self.view.frame)-(2*COLLECTION_VIEW_PADDING))/2;
    return CGSizeMake(height * (9.0/08.0), height);
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
    return self.movies.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    MovieCollectionViewCell* cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"movieCell"
                                                                           forIndexPath:indexPath];
    cell.indexPath = indexPath;
    Movie *movie = [self.movies objectAtIndex:indexPath.row];
    [cell updateCellForMovie:movie];
    return cell;
}

My next step will be on creating Apple Watch Apps.
Looking forward to hear your comments.

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *