Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate embedded youtube video to landscape mode

I am using the following embed code to embed my youtube videos on IOS

- (NSString*)embedYouTube:(NSString*)youtube_id frame:(CGRect)frame {  
   NSString* embedHTML = @"\
   <html><head>\
   <style type=\"text/css\">\
   body {\
   background-color: transparent;\
   color: white;\
   }\
   </style>\
   </head><body style=\"margin:0\">\
   <iframe src=\"http://www.youtube.com/embed/%@?rel=0\" frameborder=\"0\" allowfullscreen width=\"%0.0f\" height=\"%0.0f\"></iframe>\
   </body></html>"; 
   NSString *html = [NSString stringWithFormat:embedHTML, youtube_id, frame.size.width, frame.size.height];

   return html;
}

//code to embed video
NSString *contentHTML;
if (currentAnswer.youtube_id != nil) {
    contentHTML = [self embedYouTube:currentAnswer.youtube_id frame:CGRectMake(CELL_TEXT_LEFT_MARGIN + CELL_AVATAR_WIDTH + CELL_SPACING, currentYAxisValue, CELL_YOUTUBEVIEW_WIDTH, CELL_YOUTUBEVIEW_HEIGHT)];
}

[webView loadHTMLString: contentHTML baseURL:nil];

When I play the video, it only plays in potrait mode and not landscape mode. Is this a restriction due to the 'iframes', is there any way around this?

like image 567
Zhen Avatar asked Jun 29 '12 09:06

Zhen


People also ask

Can you rotate an uploaded YouTube video?

Double click on the video you want to edit or click once and select to move to the timeline. Choose the "Edit" option on the toolbar. To rotate, move the slider on the right side of the screen and adjust until you get your desired outcome. Click "Ok" to save or "Reset" to start over.


1 Answers

It should work provided that your UIViewController is also able to rotate to landscape.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

Test that your UIViewController is able to rotate before trying to rotate the video. If you don't want your UIViewController to be able to rotate when the video isn't on the screen, you could just do something like:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(webView && webView.superView) return YES;
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
like image 140
Michael Frederick Avatar answered Oct 04 '22 16:10

Michael Frederick