When developing a user application, there may be a necessity to play a video on the form. For example, it may be a short presentation containing information about the application, or a video that is played during execution of some long process. A video can be played by means of the built-in Windows Media player. A player can be loaded to the OleDocumentBox component. A Windows Media COM object has the MediaPlayer.MediaPlayer.1 program identifier that should be specified in the CreateObject method to create a player instance:
Class TESTForm: Form
OleDocumentBox1: OleDocumentBox;
Sub TESTFormOnCreate(Sender: Object; Args: IEventArgs);
Begin
OleDocumentBox1.CreateObject("MediaPlayer.MediaPlayer.1");
End Sub TESTFormOnCreate;
End Class TESTForm;
Then, the OleObject property can be used to control the player. Specify a file to be played:
OleDocumentBox1.OleObject.SetProperty("FileName", "C:\Video\start.avi");
By default, automatic playback is used; if it needs to be disabled, set the autoStart property to False:
OleDocumentBox1.OleObject.SetProperty("autoStart", False);
Use the Play, Pause, Stop, and other methods to control file playback:
OleDocumentBox1.OleObject.Invoke("Play", New Variant[0]);
OleDocumentBox1.OleObject.Invoke("Pause", New Variant[0]);
OleDocumentBox1.OleObject.Invoke("Stop", New Variant[0]);
For details about which functions are available when working with Windows Media player, study its object model. The description is available in MSDN.
If other players are installed on the computer that use COM object to work, the above mentioned code can be modified to work with these players.
See also: