Re: [iPhone-AppDev-Auditors] IOS - Playing youtube video from within App

1,075 views
Skip to first unread message

Jerry Edens

unread,
May 9, 2013, 5:23:28 PM5/9/13
to iphone-appd...@googlegroups.com
The UITableViewDelegate protocol has a method named:

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath;

Implement this method and it will indicate to the program which video needs to be displayed.

Best,

Jerry


On Wed, May 8, 2013 at 10:56 PM, IOSAPPNEWB <tedd...@gmail.com> wrote:
Hello

I'm very new to Objective-c development and i will like to know if there is a sample code that uses TableView when the video is clicked on it loads the youtube video.

Currently im able to load the list on the iPhone but when click, it only highlights but nothing else happens.

Is there a sample code somewhere that solves this problem or is there a solution that I need to add to my code?


Thank you in advance
newB

This is my ViewController.h file 

#import <UIKit/UIKit.h>

#import "MainViewModel.h"


@interface ViewController : UIViewController<MainViewModelDelegate, UITableViewDelegate, UITableViewDataSource>

{

    MainViewModel *modal;

    

    UITableView *tblVideos;

}


@end



This is my ViewController.M


 

#import "ViewController.h"


@implementation ViewController


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.

}


#pragma mark - View lifecycle


- (void)viewDidLoad

{

    [super viewDidLoad];

    modal=[[MainViewModel alloc] init];

    modal.delegate=self;

    tblVideos=[[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];

    [tblVideos setDelegate:self];

    [tblVideos setDataSource:self];

    [self.view addSubview:tblVideos];

}


- (void)viewDidUnload

{

    [super viewDidUnload];

    modal=nil;

    tblVideos=nil;

}


- (void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

}


- (void)viewDidAppear:(BOOL)animated

{

    [super viewDidAppear:animated];

}


- (void)viewWillDisappear:(BOOL)animated

{

[super viewWillDisappear:animated];

}


- (void)viewDidDisappear:(BOOL)animated

{

[super viewDidDisappear:animated];

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    // Return YES for supported orientations

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

    } else {

        return YES;

    }

}


#pragma ModalViewDelegate

-(void) DataLoadingFinished

{

    [tblVideos reloadData];

}


#pragma UITableView Datasource methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [modal.Videos count];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSString *identifier=@"YoutubeVideosCell";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];

    if(!cell)

    {

        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

    }

    YoutubeItem *currentItem=[modal.Videos objectAtIndex:indexPath.row];

    [cell.textLabel setText:currentItem.title];

    [cell.imageView setImage:currentItem.thumbnail];

    return cell;

}@end

--
You received this message because you are subscribed to the Google Groups "iPhone Application Development Auditors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iphone-appdev-aud...@googlegroups.com.
To post to this group, send email to iphone-appd...@googlegroups.com.
Visit this group at http://groups.google.com/group/iphone-appdev-auditors?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

IOSAPPNEWB

unread,
May 9, 2013, 8:33:15 PM5/9/13
to iphone-appd...@googlegroups.com
Hello Jerry 

Thanks for your feedback

I implemented the method as shown below (highligted in bold but still the same issue.. when clicked nothing occurs.

If you dont mind giving me the full UITableViewDelegate protocol that you mentioned please

Thanks in advance


- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath

{

}

@end

To unsubscribe from this group and stop receiving emails from it, send an email to iphone-appdev-auditors+unsub...@googlegroups.com.

IOSAPPNEWB

unread,
May 13, 2013, 1:03:03 AM5/13/13
to iphone-appd...@googlegroups.com
Hello Jerry please can you get back to me? if you do not mind?

I have the source file in dropbox 

Please send me the updated Sample file 


On Friday, May 10, 2013 7:23:28 AM UTC+10, Jerry wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to iphone-appdev-auditors+unsub...@googlegroups.com.

Jerry Edens

unread,
May 13, 2013, 9:38:31 AM5/13/13
to iphone-appd...@googlegroups.com
Ok, I will try to help you out today if I get some spare time, maybe during my lunch break.

Best,


To unsubscribe from this group and stop receiving emails from it, send an email to iphone-appdev-aud...@googlegroups.com.

Jerry Edens

unread,
May 13, 2013, 10:11:33 AM5/13/13
to iphone-appd...@googlegroups.com
In your ViewController.m file add this above the Data Source Methods:

#pragma mark - UITableViewDelegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

  

  YoutubeItem *currentItem=[modal.Videos objectAtIndex:indexPath.row];

  NSString* msg = [NSString stringWithFormat:@"You Selected the Youtube Video, %@ [id: %@]", currentItem.title, currentItem.itemId];

  

  UIAlertView* av = [[UIAlertView alloc] initWithTitle:@"didSelectRowAtIndexPath"

                                               message:msg

                                              delegate:nil

                                     cancelButtonTitle:nil

                                     otherButtonTitles:@"OK", nil];

  

  [av show];

}


Best

IOSAPPNEWB

unread,
May 13, 2013, 8:49:38 PM5/13/13
to iphone-appd...@googlegroups.com
Hello Jerry

Thank you for your swift response

I have added the UITableViewDelegate.. and it when selected the video is highlighted and a StringWithFormat appears with video ID.

Thanks for that.

my next challenge is, in that method, i need to call another viewController which loads the youtube video and plays it in the simulation.

whats the best approach to get this done Jerry?


#pragma mark - UITableViewDelegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    

    YoutubeItem *currentItem=[modal.Videos objectAtIndex:indexPath.row];

    NSString* msg = [NSString stringWithFormat:@"You Selected the Youtube Video, %@ [id: %@]", currentItem.title, currentItem.itemId];

    

    UIAlertView* av = [[UIAlertView alloc] initWithTitle:@"didSelectRowAtIndexPath"

                                                 message:msg

                                                delegate:nil

                                       cancelButtonTitle:nil

                                       otherButtonTitles:@"OK", nil];

    

    [av show];

    

    // webView is a UIWebView, either initialized programmatically or loaded as part of a xib.

    

    NSString *htmlString = @"<html><head>

    <meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head>

    <body style=\"background:#F00;margin-top:0px;margin-left:0px\">

    <div><object width=\"212\" height=\"172\">

    <param name=\"movie\" value=\"https://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&author=MobileTechReview&max-results=50\"></param>

    <param name=\"wmode\" value=\"transparent\"></param>

    <embed src=\"https://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&author=MobileTechReview&max-results=50\"

    type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"212\" height=\"172\"></embed>

    </object></div></body></html>";

    

    [webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.your-url.com"]];    

    

    

}

The code above doesnt seem to work.

Thanks Jerry.



To unsubscribe from this group and stop receiving emails from it, send an email to iphone-appdev-auditors+unsubscri...@googlegroups.com.
To post to this group, send email to iphone-appd...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages