Wednesday, 22 February 2012

Showing You Tube Video in a view.


//in .h , add 
- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame;




- (void)viewDidLoad
{
    [super viewDidLoad];
    [self embedYouTube:@"http://www.youtube.com/watch?v=fp14M7yQV-0" frame:CGRectMake(0, 44, 320, 200)];
    
}

- (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];
    UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
   // videoView.center = CGPointMake(200, 100 );
    
    [videoView loadHTMLString:html baseURL:nil];
    [self.view addSubview:videoView];
    [videoView release];
}


No comments:

Post a Comment