Now a day youtube is a very famous website for videos not only for entertainment but also for tutorials. If you want to play youtube video using iOS app you have to use Web view and write the simple code in viewDidLoad method given below:
NSString *html = @"\
UIWebView *videoView = [[UIWebView alloc] initWithFrame:CGRectMake(10.0, 80.0, 300.0, 300.0)];
[videoView loadHTMLString:html baseURL:nil];
[self.view addSubview:videoView];
- (void)viewDidLoad
{
[super viewDidLoad];
<html><head>\
<style type=\"text/css\">\
body { background-color: transparent;\
color: white; \
}\
</style>\
</head><body style=\"margin:0\">\
<iframe class=\"youtube-player\" width=\"300\" height=\"300\" src=\"http://www.youtube.com/embed/5hyy2JfuXko\" frameborder=\"0\" allowfullscreen=\"true\"></iframe>\
</body></html>";
videoView.backgroundColor=[UIColor blackColor];
videoView.scrollView.bounces=NO;[videoView loadHTMLString:html baseURL:nil];
[self.view addSubview:videoView];
}
Then you can run the app and play youtube videos :
No comments:
Post a Comment