YouTube player, AS3 and Fullscreen

YouTube player, AS3 and Fullscreen

YouTube player, AS3 y Fullscreen

In the post YouTube JavaScript Player API, I appreciated that the YouTube JavaScript API does not have any method to show the video in full screen mode. Therefore, if we want to create our own HTML controls to play the video and add a button to display it in full screen mode we will have to use the HTML5 Fullscreen API on the player. The problem is that currently no version of Internet Explorer supports HTML5 Fullscreen API. The solution that uses the player Video.js to solve this problem is that the full screen button makes the video fill the browser window in browsers that do not support Fullscreen API. It is a smart solution, but it is not Fullscreen, so the ideal solution, to solve it, would be to embed the video into a Flash using the AS3 API and to use AS3 Fullscreen mode activated from an HTML control using AS3 ExternalInterface class. But there is a drawback, according to the Stage class documentation, Flash will only start Fullscreen mode in response to a click or key press by the user in the Flash:

Fullscreen mode is initiated in response to a mouse click or key press by the user; the movie cannot change Stage.displayState without user input. Flash runtimes restrict keyboard input in Fullscreen mode. Acceptable keys include keyboard shortcuts that terminate Fullscreen mode and non-printing keys such as arrows, space, Shift, and Tab keys. (Use Fullscreen interactive mode to support input from additional keys.) Keyboard shortcuts that terminate Fullscreen mode are: Escape (Windows, Linux, and Mac), Control+W (Windows), Command+W (Mac), and Alt+F4.

I suppose that this is the reason because YouTube does not provide any method in the API to display in full screen mode the player. Therefore, the only solution would be to place a button in the Flash.

We have all the documentation about using AS3 with YouTube in YouTube ActionScript 3.0 Player API Reference and it will be the guide that I will use for the examples. The AS3 API allows you to insert into a Flash application the YouTube player without controls, chromeless player, or with controls, embedded player. If we use the chromeless player the only control that will be loaded is the play button which is overlapped over the video thumbnail that appears before playing it

We will have to use the following URL to load the chromeless player in our Flash:

To load the embedded player, we will have to use the following URL and to replace the string VIDEO_ID with the YouTube Video id:

To use the JavaScript API with Flash players, we will have to add enablejsapi=1 to the URL of the player:

Here is an example of basic use in which we load the chromeless player and add a control with which we can play or pause it, using the AS3 API. In the same way we could create the other buttons to create a custom control bar.

The code of the example is the following:

Now, I will give an example of the embedded player, but only with the required programming to show how easy it is to embed a YouTube video on our Flash application.

The code of this example is the following:

Now, I am going to create a button that allows us to put our Flash application in Fullscreen mode with the YouTube Player.

The function to set it in Fullscreen mode would be the following. We may also use the YouTube AS3 API to change the video resolution to put it in Fullscreen mode.

But the problem is not using full screen mode in a flash but putting flash in this mode from HTML, because, as we saw earlier, it is only possible through a click or key press by the user on the Flash. Therefore, the only solution would be to simulate a HTML button that can not be pressed and that is over the button that shows the Flash in Fullscreen mode in order to be pressed this by the user. If we want to create our own controls, which include the full screen button, we should check whether the browser supports HTML5 Fullscreen API. If it does not support it, it would load the Flash version of the player, if the browser supports or has the Flash player.

©2024 PoseLab SL. All rights reserved.