How to render video clips in full screen
Inside the How to play video files through DirectShow tutorial we have seen how to load and play a video clip with a video player embedded inside Audio DJ Studio: now we will see how to allow rendering video clips in full screen on a single monitor system or in a multi-monitor system.
Although DirectShow comes with a dedicate API for rendering in full screen the video renderer filter through the put_FullScreenMode method of the IVideoWindow interface, it has been found that using this approach may give several problems on Windows Vista and higher versions and would limit the possibility to go in full screen to one single monitor only so it has been decided to follow a custom solution.
The custom solution requires the container application to provide one or more borderless forms, one for each of the monitors to use, that will be used as a target window for rendering the video frames in full screen: the resizing of the form, in order to occupy the full surface of the monitor, will be managed by the component directly.
The main benefit of this custom approach is the possibility to go in full screen not only on one single monitor but in more than one monitor at the same time: the configuration of monitors to use depends upon the needs of the developer.
As a further benefit, this solution allows managing the way the full screen form will be closed by adding specific code into the container form itself: for example you could hide the full screen form through the “ESC” button on the keyboard or by double-clicking the video in full screen with the mouse. You may also add a context menu to activate when the right mouse button is pressed on the video surface.
Multi-monitor management and positioning can be activated and configured in several ways, for example through the "Display" applet of the Windows control panel or, if provided, through a specific application developed by the video card manufacturer as in the case of NVIDIA video cards whose latest driver installs the "NVIDIA contro panel". As you can see on the screenshots below, a dual monitor configuration can be managed by enabling the secondary monitor to extend the Windows desktop on its surface and by positioning the secondary monitor on the left or on the right or on any other position respect to the primary monitor:
in the sample above the primary monitor has a size of 1920×1200 pixels while the secondary monitor has a size of 1280x1024 pixels; while the primary monitor will always keep its coordinates (0, 0), the positioning of the secondary monitor will determine its screen coordinates; on the picture below, corresponding to the central picture of the screenshot above, you can see that the horizontal coordinate of the secondary monitor assumes a negative value; on the picture below, corresponding to the central picture of the screenshot above, you can see that the horizontal coordinate of the secondary monitor assumes a negative value.
After having configured the multi-monitor system as described above, Audio DJ Studio allows retrieving the multi-monitor configuration with a set of dedicated methods:
|•||The number of configured monitors that could be used for going full screen through the VideoPlayer.FullscreenMonitorCountGet method|
|•||The friendly name assigned to each monitor by the system through the VideoPlayer.FullscreenMonitorNameGet method|
|•||The positioning, expressed in screen coordinates, and the size, expressed in pixels, of each monitor through the VideoPlayer.FullscreenMonitorPositionGet method|
As mentioned at the beginning of this tutorial, the container application needs to provide one or more borderless forms, one for each of the monitors to use, that will be used as a target window for rendering the video frames in full screen: the container application doesn't have to mind about the positioning and size of these borderless forms because this will be managed automatically and internally by the component.
After having enumerated the available monitors you can predispose each of them for going full screen: through the VideoPlayer.FullscreenMonitorPredispose method you can tell to the component which of the borderless forms instanced by the container application will be used for rendering the video clip in full screen; note that the call to this method will not immediately start the full screen rendering: for this purpose you will have to call the VideoPlayer.FullscreenMonitorActivate method at a later time and the same method could be also used to exit the full screen mode. You can programmatically know if a specific monitor is currently rendering a video clip in full screen through the VideoPlayer.FullscreenMonitorIsActivated method.
Once you won't need anymore using a specific monitor for full screen rendering, you could remove it from the list of predisposed monitors and save some resource through the VideoPlayer.FullscreenMonitorRemove method.
During the life of the container application, the monitor configuration could be manually changed, for example by moving the secondary screen to a different position respect to the primary monitor or by disabling the desktop's extension on the secondary monitor: the component can detect when the configuration of system monitors changes and inform the container application of the change through the DisplayConfigurationChanged event: when this situation happens, the rendering of the video clip could result frozen so the following operations will be needed:
|•||closing the video clip through the VideoPlayer.Close method|
|•||if one or more monitors were already rendering in full screen, deactivating the full screen mode for each of them through the VideoPlayer.FullscreenMonitorActivate method|
|•||removing all of the predisposed monitors through the VideoPlayer.FullscreenMonitorRemove method|
|•||predisposing again the needed monitors through the VideoPlayer.FullscreenMonitorPredispose method|
|•||reloading the video clip (for example through the VideoPlayer.Load method) in order to create an updated filters graph that will take count of the new monitors.|
An example of use of full screen and multi-monitor management in Visual C# and Visual Basic.NET can be found inside the VideoPlayerAdvanced sample installed with the product's setup package; this sample shows also how the container application can allocate and provide the borderless forms used for going full screen and how to manage an eventual change of the monitors configuration.