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?
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.
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);
}
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