Guest User

Untitled

a guest
Jan 12th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. //
  2. // RootViewController.m
  3. // YoutubeApi
  4. //
  5. // Created by Joshua Moore on 4/9/11.
  6. // Copyright 2011 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "RootViewController.h"
  10.  
  11. @interface RootViewController (PrivateMethods)
  12. - (GDataServiceGoogleYouTube *)youTubeService;
  13. @end
  14.  
  15.  
  16. @implementation RootViewController
  17.  
  18. @synthesize feed;
  19.  
  20. - (IBAction)back{
  21. [self.navigationController popViewControllerAnimated:YES];
  22. }
  23.  
  24. - (void)viewDidLoad {
  25. NSLog(@"loading");
  26.  
  27. GDataServiceGoogleYouTube *service = [self youTubeService];
  28.  
  29. NSString *uploadsID = kGDataYouTubeUserFeedIDFavorites;
  30. NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"computerclan"
  31. userFeedID:uploadsID];
  32.  
  33. [service fetchFeedWithURL:feedURL
  34. delegate:self
  35. didFinishSelector:@selector(request:finishedWithFeed:error:)];
  36.  
  37. [super viewDidLoad];
  38. }
  39.  
  40. - (void)request:(GDataServiceTicket *)ticket
  41. finishedWithFeed:(GDataFeedBase *)aFeed
  42. error:(NSError *)error {
  43.  
  44. self.feed = (GDataFeedYouTubeVideo *)aFeed;
  45.  
  46. [self.tableView reloadData];
  47. }
  48.  
  49.  
  50. #pragma mark Table view methods
  51.  
  52. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  53. return 1;
  54. }
  55.  
  56.  
  57. // Customize the number of rows in the table view.
  58. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  59. return [[feed entries] count];
  60. }
  61.  
  62. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  63. {
  64. return 70.0f;
  65. }
  66.  
  67.  
  68. // Customize the appearance of table view cells.
  69. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  70.  
  71. static NSString *CellIdentifier = @"Cell";
  72.  
  73. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  74. if (cell == nil) {
  75. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  76. }
  77.  
  78. // Configure the cell.
  79. GDataEntryBase *entry = [[feed entries] objectAtIndex:indexPath.row];
  80. NSString *title = [[entry title] stringValue];
  81. NSArray *thumbnails = [[(GDataEntryYouTubeVideo *)entry mediaGroup] mediaThumbnails];
  82.  
  83. cell.textLabel.text = title;
  84.  
  85.  
  86.  
  87. NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[thumbnails objectAtIndex:0] URLString]]];
  88. cell.imageView.image = [UIImage imageWithData:data];
  89.  
  90. return cell;
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. - (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {
  100. NSString *embedHTML = @"\
  101. <html><head>\
  102. <style type=\"text/css\">\
  103. body {\
  104. background-color: transparent;\
  105. color: white;\
  106. }\
  107. </style>\
  108. </head><body style=\"margin:0\">\
  109. <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
  110. width=\"%0.0f\" height=\"%0.0f\"></embed>\
  111. </body></html>";
  112. NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
  113. [webView7 loadHTMLString:html baseURL:nil];
  114. }
  115.  
  116.  
  117. - (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
  118.  
  119. GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row];
  120. NSArray *contents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
  121.  
  122. NSString *vidTitle = [[entry2 title] stringValue];
  123. title2.text = vidTitle;
  124.  
  125.  
  126.  
  127. [self.navigationController pushViewController:secondViewController animated:YES];
  128.  
  129. [self embedYouTube:[NSURL URLWithString:[[contents objectAtIndex:0] URLString]]
  130. frame:CGRectMake(70, 100, 200, 200)];
  131.  
  132. }
  133.  
  134.  
  135. - (void)dealloc {
  136. [super dealloc];
  137. }
  138.  
  139.  
  140. - (GDataServiceGoogleYouTube *)youTubeService {
  141. static GDataServiceGoogleYouTube* _service = nil;
  142.  
  143. if (!_service) {
  144. _service = [[GDataServiceGoogleYouTube alloc] init];
  145.  
  146. [_service setUserAgent:@"AppWhirl-UserApp-1.0"];
  147. [_service setShouldCacheDatedData:YES];
  148. [_service setServiceShouldFollowNextLinks:YES];
  149. }
  150.  
  151. // fetch unauthenticated
  152. [_service setUserCredentialsWithUsername:nil
  153. password:nil];
  154.  
  155. return _service;
  156. }
  157.  
  158. @end
Add Comment
Please, Sign In to add comment