I am trying to get YouTube functioning within my iOS App. I am successfully retrieving the list of videos for a particular user, but I am struggling to implement the didSelectRowAtIndexPath in order to get the selected video to embed in a separate viewController. Here is the code I am having trouble with:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detailController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailController"];
GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row];
videoArray = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
NSString *tempUrl = [videoArray objectAtIndex:0];
NSLog(@"The URL is:%@",tempUrl);
detailController.videoString = tempUrl;
[self.navigationController pushViewController:detailController animated:YES];
}
Every time I run this, I get a breakpoint at 'detailController.videoString = tempUrl;'
I am able to see the tempUrl string is being populated with the following via NSLog:
The URL is:GDataMediaContent 0x69c76a0: {url:https://www.youtube.com/v/s36krFdPmYQ?version=3&f=user_uploads&app=youtube_gdata type:application/x-shockwave-flash medium:video isDefault:true expression:full duration:1913}
How can I extract just the video URL from the GData API?
Thanks in advance for your responses.
I made the following changes and I am now getting a proper URL string:
GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row];
NSArray *mediaContents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
GDataMediaContent *flashContent = [GDataUtilities firstObjectFromArray:mediaContents withValue:@"application/x-shockwave-flash" forKeyPath:@"type"];
NSLog(@"The URL is:%@",[flashContent URLString]);
detailController.videoString = [flashContent URLString];
Which gives me the following from NSLog:
The URL is:https://www.youtube.com/v/s36krFdPmYQ?version=3&f=user_uploads&app=youtube_gdata
I am still however getting a breakpoint at 'detailController.videoString = [flashContent URLString];
I was able to solve this. I added a Modal segue between the two ViewControllers and also modified my code slightly. Here is the code I ended up using after adding the segue:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detailController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailController"];
GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row];
NSString *title = [[entry2 title] stringValue];
NSArray *contents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
GDataMediaContent *flashContent = [GDataUtilities firstObjectFromArray:contents withValue:@"application/x-shockwave-flash" forKeyPath:@"type"];
NSString *tempURL = [flashContent URLString];
detailController.videoString = tempURL;
detailController.titleString = title;
[self.navigationController pushViewController:detailController animated:YES];
}
You can view the full working YouTubeDemo app code here: https://gist.github.com/2501684