I've embedded a video from YouTube via a snippet I've found on the Internet, here is the code that I've used:
@interface FirstViewController (Private) - (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame; @end @implementation FirstViewController - (void)viewDidLoad { [super viewDidLoad]; [self embedYouTube:@"http://www.youtube.com/watch?v=l3Iwh5hqbyE" frame:CGRectMake(20, 20, 100, 100)]; } - (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 loadHTMLString:html baseURL:nil]; [self.view addSubview:videoView]; [videoView release]; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } @end
It compiles correctly and when I open it, I see a white box positioned incorrectly, which the code created. I have two questions regarding it:
How do I know if the video will play, it is just a plain white box, does the simulator play videos from YouTube?
How can I position this box?
Yes, it's legal to embed the content. You're not hosting the content, and you didn't steal the content. You have some responsibility to do at least some due diligence to find the original owner of any piece of content you want to reference or use, but you aren't required to go out of your want for it.
Allow (and Encourage) People to Embed Your Videos Allowing embedding means that people can re-publish your video on their website, blog, or channel, which will help you gain even more exposure.
To begin, let's first answer your question, “What does embedding a video mean?” Embedding lets you place a video directly into your website for users to view without having to leave to play it on another page.
Just tested your code, it works fine on an iPhone, Youtube videos are not supported on the iOS simulator though, so you'll need a real device for testing.
How can I position this box?
You are already passing the X (20), Y(20), width(100) and height(100) of the box at this line:
[self embedYouTube:@"http://..." frame:CGRectMake(20, 20, 100, 100)];
To change the position of the view afterwards, you modify its center property:
videoView.center = CGPointMake(200, 100 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With