0

I am embedding Youtube videos in my app using UIWebView. I want everything in my app portrait mode only except when playing Youtube video. I have googled it but I havent solved it. My app just has 1 UIViewController (UINavigationController embedded) display 1 UIWebView.

I have tried a solution in here iPhone rotation and full-screen video and here Fullscreen youtube video, rotation, and the status bar (iOS) but not solved yet.

Here is my code in ViewDidLoad:

NSString *videoId = @"nzNkUhvq43A";
NSString *videoUrl =[NSString stringWithFormat:@"src=\"http://www.youtube.com/embed/%@\"",     videoId];

NSString *htmlString =[NSString stringWithFormat:@"<iframe width=\"256\" height=\"144\" %@ frameborder=\"0\" allowfullscreen></iframe>", videoUrl];
NSLog(@"%@", htmlString);
myWebView.scrollView.scrollEnabled = NO;
myWebView.scrollView.bounces = NO;
[myWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]];

Thanks.

Community
  • 1
  • 1
Tin Ten
  • 3
  • 1
  • 3

1 Answers1

-1

UPD2: Solution in this

Added to your project lite fix in AppDelegate and share it this.

Community
  • 1
  • 1
Bimawa
  • 3,535
  • 2
  • 25
  • 45
  • Thank you for replying. Could you give me code sample? I googled and followed this http://stackoverflow.com/questions/6461020/ios-willrotatetointerfaceorientation-proper-usage but still not solved yet. – Tin Ten Jun 05 '13 at 15:56
  • I put it in my code and it seems doesn't change anything in my app. I still could rotate everything. If I put your code in and I also uncheck Landscape Left and Landscape Right in Supported Interface Orientations, everything works fine but I can't rotate while playing Youtube video. Did I miss something? – Tin Ten Jun 06 '13 at 10:47
  • it's very strange for me. I archive test project and put it to Cloud. http://cl.ly/1C2x222j1P3u pls play with it. Maybe that help for you... – Bimawa Jun 06 '13 at 11:08
  • Thank you very much. I have downloaded your project. But when I run it, I can rotate left or right :D. What I want is everything in my app cannot rotate left or right except when I play Youtube Video. – Tin Ten Jun 06 '13 at 11:21
  • Damn... how you run apps? on Simulator or Device? For rotate simulator push cmd+-> or cmd-< , on Device just rotate it... in my project all work fine.. i play youtube and after that i rotating py simulator and all rotatet in UIWebView too. – Bimawa Jun 06 '13 at 15:11
  • I run on Simulator. Let check my project here http://www.mediafire.com/?kzc1575yhb4rzuf . I did as you did in your project but I still can rotate my app. I dont want my app be able to rotate, I want it run on portrait mode only but it CAN rotate left or right when playing Youtube video. For my project now, when I dont play Youtube video I still can rotate left or right. Thank you for your support. – Tin Ten Jun 06 '13 at 16:51
  • Wow, it is very helpful to me but... as someone in your new solution said: "Just keep in mind that using private notifications (UIMoviePlayerControllerDidEnterFullscreenNotification and UIMoviePlayerControllerWillExitFullscreenNotification) could break in future iOS releases or cause an App Store rejection.". Should I use that solution or try to find another better solution? I really need your advice bro :D. – Tin Ten Jun 07 '13 at 04:19
  • :))) You can think of it in the future ^_^. the main solution to the problem hiding in AppDelegate. p.s. nice voice on video song ^_^ – Bimawa Jun 07 '13 at 04:53
  • :)) ok thank you very much. I will put it aside and develop the main features of my app :D. – Tin Ten Jun 07 '13 at 12:16
  • Ohh i lose the file. mb @Tin-Ten have a copy? – Bimawa Sep 18 '13 at 03:21