Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // RootViewController.m
- // YoutubeApi
- //
- // Created by Joshua Moore on 4/9/11.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import "RootViewController.h"
- @interface RootViewController (PrivateMethods)
- - (GDataServiceGoogleYouTube *)youTubeService;
- @end
- @implementation RootViewController
- @synthesize feed;
- - (IBAction)back{
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)viewDidLoad {
- NSLog(@"loading");
- GDataServiceGoogleYouTube *service = [self youTubeService];
- NSString *uploadsID = kGDataYouTubeUserFeedIDFavorites;
- NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"computerclan"
- userFeedID:uploadsID];
- [service fetchFeedWithURL:feedURL
- delegate:self
- didFinishSelector:@selector(request:finishedWithFeed:error:)];
- [super viewDidLoad];
- }
- - (void)request:(GDataServiceTicket *)ticket
- finishedWithFeed:(GDataFeedBase *)aFeed
- error:(NSError *)error {
- self.feed = (GDataFeedYouTubeVideo *)aFeed;
- [self.tableView reloadData];
- }
- #pragma mark Table view methods
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- // Customize the number of rows in the table view.
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [[feed entries] count];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 70.0f;
- }
- // Customize the appearance of table view cells.
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
- }
- // Configure the cell.
- GDataEntryBase *entry = [[feed entries] objectAtIndex:indexPath.row];
- NSString *title = [[entry title] stringValue];
- NSArray *thumbnails = [[(GDataEntryYouTubeVideo *)entry mediaGroup] mediaThumbnails];
- cell.textLabel.text = title;
- NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[thumbnails objectAtIndex:0] URLString]]];
- cell.imageView.image = [UIImage imageWithData:data];
- return cell;
- }
- - (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {
- NSString *embedHTML = @"\
- <html><head>\
- <style type=\"text/css\">\
- body {\
- background-color: transparent;\
- color: white;\
- }\
- </style>\
- </head><body style=\"margin:0\">\
- <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
- width=\"%0.0f\" height=\"%0.0f\"></embed>\
- </body></html>";
- NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
- [webView7 loadHTMLString:html baseURL:nil];
- }
- - (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
- GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row];
- NSArray *contents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
- NSString *vidTitle = [[entry2 title] stringValue];
- title2.text = vidTitle;
- [self.navigationController pushViewController:secondViewController animated:YES];
- [self embedYouTube:[NSURL URLWithString:[[contents objectAtIndex:0] URLString]]
- frame:CGRectMake(70, 100, 200, 200)];
- }
- - (void)dealloc {
- [super dealloc];
- }
- - (GDataServiceGoogleYouTube *)youTubeService {
- static GDataServiceGoogleYouTube* _service = nil;
- if (!_service) {
- _service = [[GDataServiceGoogleYouTube alloc] init];
- [_service setUserAgent:@"AppWhirl-UserApp-1.0"];
- [_service setShouldCacheDatedData:YES];
- [_service setServiceShouldFollowNextLinks:YES];
- }
- // fetch unauthenticated
- [_service setUserCredentialsWithUsername:nil
- password:nil];
- return _service;
- }
- @end
Add Comment
Please, Sign In to add comment