Bojan Bozovic
Bojan Bozovic

Reputation: 910

Javascript command to get youtube player in fullscreen (iOS)?

I need to display youtube videos in iframe similar to one in official Youtube app. When device is rotated to landscape, video should be played in fullscreen mode.

I use this code for embedding youtube videos, however I'm not sure how to force fullscreen mode in landscape:

NSString* embedHTML = [NSString stringWithFormat:@"

                       <html>
                       <body style='margin:0px;padding:0px;'>
                       <script type='text/javascript' src='http://www.youtube.com/iframe_api'></script>
                       <script type='text/javascript'>
                       function onYouTubeIframeAPIReady()
                       {
                       ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})
                       }
                       function onPlayerReady(a)
                       { 
                       a.target.playVideo(); 
                       }
                       </script>
                       <iframe id='playerId' type='text/html' width='%f' height='%f' src='http://www.youtube.com/embed/%@?enablejsapi=1&rel=0&playsinline=1&autoplay=1' frameborder='0'>
                       </body>
                       </html>", self.webView.frame.size.width, self.webView.frame.size.height, self.videoId];

[self.webView loadHTMLString:embedHTML baseURL:[[NSBundle mainBundle] resourceURL]];

And I get this inline player:

enter image description here

which has fullscreen button. I want to trigger fullscreen from code.

Is there any javascript command for switching from inline to fullscreen mode?

Example:Youtube offical app Portrait:

enter image description here

and landscape:

enter image description here

How to achieve this?

Upvotes: 2

Views: 1771

Answers (1)

camimvogelsang
camimvogelsang

Reputation: 289

If you want to search/query a youtube video, check out GData to retrieve the video URL.

To play the video in full screen, I would extract the video URL from the javascript and use XCDYoutubeVideoPlayerViewController to play it fullscreen.

Upvotes: 1

Related Questions