ActiveMovie ControlActiveMovie Control*
*



Contents  *



Index  *Topic Contents
*Previous Topic: Component Library
*Next Topic: Control Properties

ActiveMovie Control


This section explains how to use the Microsoft® ActiveMovie™ Control, both in HTML pages and in Visual Basic applications. It contains a description of the control properties, methods, events, property sheet, and shortcut keys.

arrowb.gifIntroduction to DirectShow

arrowb.gifAbout the DirectShow ActiveMovie Control

arrowb.gifUsing the ActiveMovie Control in HTML Pages

arrowb.gifUsing the ActiveMovie Control in Visual Basic

arrowb.gifControl Properties

arrowb.gifControl Methods

arrowb.gifControl Events

arrowb.gifControl Property Sheet

arrowb.gifControl Shortcut Keys

Introduction to DirectShow

Microsoft® DirectShow™ is an extensible media architecture that delivers high-quality audio and video playback from the Internet or an intranet. DirectShow supports the most popular media types, including MPEG audio and video, AVI video, WAV audio, MIDI audio, and Apple® QuickTime® video. You can access the DirectShow-supported media types quickly and easily by using the Microsoft ActiveMovie™ Control.

The DirectShow architecture defines how applications can control and process time-stamped multimedia data using modular components called filters connected in a configuration called a filter graph. A complete filter graph consists of a number of filters, assembled in a logical progression from the data source to the media renderer or renderers.

Applications assemble the filter graph and control how data moves through it by accessing the filter graph manager through programming interfaces, as shown in the following illustration.

Diagram of how information moves between DirectShow and an application

For example, the Microsoft MPEG filter graph uses the following filters.

Default filter graphs are configured for you when you install the DirectShow software on your computer. You can also install additional filters and create your own filter graphs. For more information about creating and managing filter graphs, see Filter Graph Manager and Filter Graphs in the DirectShow SDK documentation.

About the DirectShow ActiveMovie Control

You can use the DirectShow ActiveMovie Control to quickly add support for multimedia to your applications. DirectShow supports the many media types, including MPEG audio and video, AVI video, WAV audio, MIDI audio, and Apple® QuickTime® video. The DirectShow SDK provides samples and examples that illustrate how to write programs that use the control with either Microsoft® Visual Basic® or Microsoft Visual C++®.

The ActiveMovie Control represents an easy-to-use programming interface that lets you manage multimedia using the control's properties, methods, and events. The control handles all video and audio rendering for you, which simplifies your programming tasks and makes it easy to add support for multimedia to your application. In addition to the ActiveMovie Control, you can use the DirectShow Component Object Model (COM) interfaces. (See Summary of DirectShow COM Interfaces in the DirectShow SDK documentation.)

Using the ActiveMovie Control in HTML Pages

Files on a Web page are referenced using URL names and various protocols, such as HTTP, file, FTP, or Gopher. These names can be either explicit or relative.

Following are two examples of explicit references. The first example uses the HTTP protocol to access the file. The second uses a network path and file name.

"http://directshow/samples/web/RoadRun.avi"

"file://directshow/samples/web/RoadRun.avi"

Here is an example of a relative reference:

"/samples/web/RoadRun.avi"

In the examples in this article, you can assume that either relative or explicit file names will work and any protocol for accessing these file names will also work.

Contents of this article:

Invoking Playback on HTML Pages

You can play files in one of two ways: either embedded in a Web page, or externally in a window displayed outside or on top of the page. There are four ways of playing back media using HTML tags. Three of these result in embedded playback:

The fourth means of implementing playback results in an external window:

Although not restricted to playback, you can use an attribute of the OBJECT tag to automatically download a file that contains required components for playback.

The following examples show how you use these tags to reference the file, but do not show all possible properties and attributes (width, height, color, and so on) that could be specified as well. See Setting ActiveMovie Control Properties on a Web Page for more information.

Using the OBJECT Tag

When you use the OBJECT tag, you must explicitly specify the class identifier (CLSID) for the playback control, as shown in the following example.

<OBJECT CLASSID="CLSID:05589FA1-C356-11CE-BF01-00AA0055595A">
<PARAM NAME="FileName" VALUE="http://www.microsoft.com//directshow/samples/web/RoadRun.avi">
</OBJECT>

The preceding CLSID is that of the ActiveMovie Control. The application loads the control and passes it the file name. The control parses the file name and downloads and plays the file. If the protocol is "file," the control instantiates the File Source (async) filter to play back the file. If the protocol is "http," the control instantiates the File Source (URL) filter instead. See the DirectShow SDK documentation for more information on these filters.

Using this tag, you can play back certain media types using "progressive downloading," which allows the user to play back the downloaded portion of the file as the data is downloading. See How Progressive Downloading Works for more information.

Using this tag along with the CODEBASE attribute, you can download components required for playback. See Using the OBJECT Tag with the CODEBASE Attribute for more information.

Using the OBJECT Tag with the CODEBASE Attribute

As the author of a Web page, you might find that using components such as specialized DirectShow filters can enhance playback of your media files on the user's machine. However, if the necessary components aren't already installed on the user's computer, you need a method to install those components. Internet Explorer supports using the CODEBASE attribute of the OBJECT tag for automatic file download, and cabinet (.cab) files for automatic installation. See http://www.microsoft.com/workshop/prog/cab/default.htm for information about the Cabinet SDK and .cab files.

The CODEBASE attribute works in conjunction with the OBJECT tag. See Using the OBJECT Tag for another example that uses the OBJECT tag.

An example of filter download using the CODEBASE attribute and a .cab file follows:

<OBJECT ID=GargleFilter1
CLASSID="CLSID:d616f350-d622-11ce-aac5-0020af0b99a3"
CODEBASE="http://directshow/samples/gargle.cab">
</OBJECT>

The preceding class identifier (CLSID) is the ID of the Gargle filter, which applies a "gargle" sound effect to a sound file. Internet Explorer checks the target computer's registry for the specified CLSID. If the specified CLSID is not present (indicating the filter is not installed on the machine), the browser attempts to find the file (Gargle.cab) at the site specified by the CODEBASE attribute and download it. Once downloaded, the .cab file provides the information to automatically install the filter.

Note: The .cab file must have been properly constructed for automatic installation to work. The .cab must include the filter (Gargle.ax in this case) and an .inf file that contains installation information. The .inf file should handle copying each filter to a specific directory (such as the Windows® System directory) on the user's computer and properly registering each filter. See the Platform SDK for information about .inf files.

Using the EMBED Tag

Netscape introduced this tag for embedding source. The following example uses this tag.

<EMBED autostart="FALSE" loop="FALSE" SRC="http://directshow/samples/web/RoadRun.avi">

This tag works identically to the OBJECT tag, except that you don't need to specify the CLSID. Internally, DirectShow examines the HKCR/MIME/Database/Content Type registry entries, retrieves the appropriate CLSID (DirectShow automatically registers all compatible data types at install time), and launches the control with that media type.

Using the IMG tag with the DYNSRC= Attribute

Internet Explorer can use the DYNSRC= attribute to play back audio-video interleaved (AVI) files. You can use this playback mechanism, but it is preferable to use the OBJECT tag. The following example demonstrates this HTML tag.

<IMG start=1 loop=0 DYNSRC="http://directshow/samples/web/RoadRun.avi">

Using the A Tag with the HREF Attribute

To play back a movie in an external movie, use the A tag with the HREF attribute. An example of this follows:

<A HREF="http://directshow/samples/web/dwad.cinepack.avi">AVI_CINEPACK</A>

The parsing steps that Internet Explorer 3.0 (or later) goes through are similar to the "EMBED SRC tag" case, in that it gets the file extension, maps it to a content type and looks in the HKCR/MIME/Database/Content Type area of the registry to get a CLSID to invoke. However, in this case the control plays in an external window. The ActiveMovie Control is in control of downloading the file.

How Progressive Downloading Works

The following series of steps describes what happens during progressive downloading.

  1. As soon as possible after activation, the ActiveMovie Control displays the first frame in the file (for movies). The filter graph remains in a paused state.
  2. The control does not start to play until it determines that it has enough data to play uninterrupted while the remaining amount downloads. At this time, playback starts and downloading will continue.
  3. The user can click the Play button during this time. In this case, the control will play until the play cursor reaches the end of the current amount downloaded and will automatically transition from the running state to the paused state.
  4. The download of the file will not stop if the user clicks Stop. The user can stop the download by closing the control.
  5. For most AVI or QuickTime files, you can't start playback until DirectShow has read the entire file (because the indexes are at the end of the file). However, the download bar is displayed to show how much of the file has been downloaded. The Play control button remains unavailable until the control downloads the file completely.

Setting ActiveMovie Control Properties on a Web Page

You can set any ActiveMovie Control property by using the PARAM tag inside an OBJECT container. For Boolean values, –1 is TRUE and 0 is FALSE. All other values are set as they would be in the Microsoft® Visual Basic® design environment.

The following example demonstrates playing a movie with most controls shown. If you have a video file and you want to try this, you can copy and paste this code onto your Web page and modify the parameters as you want. If you do this, be sure to change the movie's file name, perhaps using a relative path and file protocol (for example, PARAM NAME="FileName" VALUE="file://c:\mymovie.mpg") to play the movie from your hard drive.

<HTML>
<HEAD>
<TITLE>ActiveMovie Embedded MPG Object Test Page</TITLE>
</HEAD>
<BODY>
Scene from Stargate (MPG File)
<OBJECT ID="ActiveMovie1" WIDTH=357 HEIGHT=322
CLASSID="CLSID:05589FA1-C356-11CE-BF01-00AA0055595A">
<PARAM NAME="Version" VALUE="1">
<PARAM NAME="EnableContextMenu" VALUE="-1">
<PARAM NAME="ShowDisplay" VALUE="-1">
<PARAM NAME="ShowControls" VALUE="-1">
<PARAM NAME="ShowPositionControls" VALUE="0">
<PARAM NAME="ShowSelectionControls" VALUE="0">
<PARAM NAME="EnablePositionControls" VALUE="-1">
<PARAM NAME="EnableSelectionControls" VALUE="-1">
<PARAM NAME="ShowTracker" VALUE="-1">
<PARAM NAME="EnableTracker" VALUE="-1">
<PARAM NAME="AllowHideDisplay" VALUE="-1">
<PARAM NAME="AllowHideControls" VALUE="-1">
<PARAM NAME="MovieWindowSize" VALUE="0">
<PARAM NAME="FullScreenMode" VALUE="0">
<PARAM NAME="MovieWindowWidth" VALUE="353">
<PARAM NAME="MovieWindowHeight" VALUE="318">
<PARAM NAME="AutoStart" VALUE="0">
<PARAM NAME="AutoRewind" VALUE="-1">
<PARAM NAME="PlayCount" VALUE="1">
<PARAM NAME="SelectionStart" VALUE="0">
<PARAM NAME="SelectionEnd" VALUE="48.5151388">
<PARAM NAME="Appearance" VALUE="1">
<PARAM NAME="BorderStyle" VALUE="1">
<PARAM NAME="FileName" VALUE="http://DirectShow/samples/web/stargate1.mpg">
<PARAM NAME="DisplayMode" VALUE="0">
<PARAM NAME="AllowChangeDisplayMode" VALUE="-1">
<PARAM NAME="DisplayForeColor" VALUE="16777215">
<PARAM NAME="DisplayBackColor" VALUE="0">
</OBJECT>
</BODY>

Using the ActiveMovie Control in Visual Basic

This article describes how Microsoft® Visual Basic® applications can use the ActiveMovie Control. The ActiveMovie Control is a high-level interface that meets the needs of most multimedia application developers. Additional lower-level interfaces are also available to Visual Basic programmers.

Contents of this article:

Quick Start: Insert and Use the ActiveMovie Control

This section describes how to insert the ActiveMovie Control and use it in a Visual Basic application. It is a simple example to get you started, and implements only playing and stopping a movie.

Follow these steps to insert the ActiveMovie Control into a Visual Basic form and play a movie:

  1. Install Internet Explorer to install the ActiveMovie Control.
  2. Open a project or create a new project in Visual Basic.
  3. Choose Components from the Projects menu. Choose the Controls tab. If the ActiveMovie Control does not appear in the list of Controls, click the Browse button. In the Add ActiveX Control dialog box that appears, navigate to the directory containing the control (by default, the \Windows\System or \Winnt\System32 directory). Double-click the Amovie.ocx file to add the ActiveMovie Control to the Controls list.
  4. Add the ActiveMovie Control to the Visual Basic toolbox by selecting the check box next to Microsoft ActiveMovie Control in the Controls list.
  5. Add the ActiveMovie Control to your form and size the control to the screen size you want for your movie. (Click the control in the Toolbox, and then draw its size on the form.)
  6. In the Properties list for the ActiveMovie Control, initialize the FileName property to the movie file you want to play. The FileName property should contain the full path. For example:
    c:\movies\mymovie.avi
    
  7. Set the ShowControls and ShowDisplay properties to FALSE.
  8. Add code to start and stop the movie to two events the ActiveMovie Control supports. For example:
    Private Sub ActiveMovie1_Click()
        ActiveMovie1.Run
    End Sub
    Private Sub ActiveMovie1_KeyPress(KeyAscii As Integer)
         ActiveMovie1.Stop
    End Sub 
    
  9. Compile the application.
  10. Run the application. In this example, click anywhere on the movie screen to start the movie. Press any key to stop the movie.

Follow these steps to use the ActiveMovie Control to play a movie controlled by Visual Basic controls:

  1. Follow steps 1-6 as shown earlier in this section.
  2. Add Visual Basic controls (such as a CommandButton or ListBox) to your form to play and stop the movie.
  3. Add code to play and stop the movie. For example:
    Private Sub Command1_Click()
    ActiveMovie1.Run
    End Sub
    Private Sub Command2_Click()
    ActiveMovie1.Stop
    End Sub
    
  4. Compile the application.
  5. Run the application. In this example, Click the Command1 button to start the movie. Click the Command2 button to stop the movie.

The Visual Basic Ocxvb01 Sample

This section describes some of the features of the DirectShow Visual Basic sample application called Ocxvb01 in the VB\OCX directory of the DirectShow samples. The ActiveMovie Control manages most of the details of the display and playback of DirectShow files, while giving the Visual Basic developer control over the image size, playback rate, volume, balance, and position. With the control, the developer can manage a variety of standard user interface controls, such as rewind and fast forward, and a trackbar control to set positions within the media file.

The Visual Basic sample application Ocxvb01 consists of two forms: the main control form frmMain (Ocxvb01.frm) and the display form frmViewer (Viewer.frm).

The frmMain form's menu commands call ActiveMovie Control methods to run, pause, and stop multimedia playback, set and retrieve the control's properties, and enable and disable different parts of the user interface.

The frmMain form contains two command buttons that change the CurrentPosition property of the IMediaPosition object; you can use these buttons to move forward or backward through the multimedia source file, if the multimedia source type supports this functionality. The frmMain form's trackbar control sets the Playback property; its valid range is 0.5 to 1.5. This value is used as a multiplier; 1.0 is the authored speed, so 0.5 is half the authored speed and 2.0 is twice the authored speed. You can set this property to values outside this range, but the audio portion tends to become incomprehensible.

The main control form also contains option buttons that set the display configuration to half size, full size (default), and double size. The main control form appears as shown in the following illustration.

Main control form

The display form, frmViewer, contains the ActiveMovie Control that is displayed when the DirectShow multimedia source file is active or when the source is playing. The application resizes the display form to correspond to the selected source. The display form, with all ActiveMovie Control user interface elements visible and enabled, appears as shown in the following illustration.

Display form with all ActiveMovie Control elements visible and enabled

The following sections describe how to use some of the properties, methods, and events.

Opening and Running DirectShow Source Files

To load and play a DirectShow file, set the ActiveMovie Control's FileName property. Depending on your application's requirements, you can play the file from your code by using methods like Run and Stop, or you can let the user interact with the user interface elements offered by the control.

The FileName property specifies the name of the multimedia source file. When you set the FileName property, several other properties are updated to indicate characteristics of that source file.

Once the FileName property contains a valid file name, you can call the control's Run method to play the multimedia file. Or, you can enable the control buttons on the display form and let the user play the file.

The sample application contains an Open command on the File menu that sets the value of the FileName property. It invokes the File Open common dialog box to obtain a file name:

 
   Private Sub mnu_File_Open_Click() 
 
      CommonDialog1.Filter = "All files (*.*)|*.*|DirectShow files 
(*.mpg;*.mpa;*.mpv;*.mov;*.mpeg;*.enc;*.m1v;*.mp2)|*.mpg;*.mpa;*.mpv;*.mov;*.mpeg;*.enc;*.m1v;*.
mp2|Audio files (.wav)|*.wav|Video for Windows files 
(.avi)|*.avi" 
      CommonDialog1.Flags = 4 'Hide read-only check box 
      CommonDialog1.ShowOpen 
      ' only set the property if the user selected a filename from the common dialog
      If CommonDialog1.filename <> "" Then 
         frmViewer.ActiveMovie1.filename = CommonDialog1.filename 
         g_FileOpened = True 
         g_FileExtension = Right$(CommonDialog1.filename, Len(CommonDialog1.filename) - 
InStr(CommonDialog1.filename, ".")) 
      Else 
         GoTo err_FileOpen 
      End If 
      Call ResizeViewer 
      ... 
 

First, the subroutine prepares the common dialog box to display only movie files. After the common dialog box returns, the subroutine checks to determine if a file name was returned.

If a file name was returned, the subroutine sets the FileName property of the ActiveMovie Control, in addition to some other global variables: gFileOpened to determine whether or not a file has been opened, and gFileExtension to determine the type of the file.

Finally, the subroutine calls the ResizeViewer subroutine to make the dimensions of the viewer form match those of the DirectShow file. The dimensions of the Visual Basic form are expressed in twips, while the dimensions of the multimedia source are expressed in pixels. The ResizeViewer subroutine considers these differences to size the form by using the form's ScaleHeight and ScaleWidth properties:

' Resize form to dimensions of ActiveMovie Control + nonclient region.
    With frmViewer
        .Visible = False
        .Height = .ActiveMovie1.Height + (.Height - .ScaleHeight)
        .Width = .ActiveMovie1.Width + (.Width - .ScaleWidth)
        .Visible = True
    End With

After the file is loaded successfully, you can play it by clicking Play on the control, or by using the Run method. The sample application provides a Run command on its File menu that calls the Run method:

 
   Private Sub mnu_File_Run_Click() 
 
      If g_FileOpened = True Then 
         frmViewer.ActiveMovie1.Run 
         frmViewer.ZOrder 0 
      End If 

Managing the User Interface of the ActiveMovie Control

The display form of the sample application (Viewer.frm) contains the ActiveMovie Control. The following illustration shows the control with the status bar visible and the control bar hidden.

ActiveMovie Control with status bar visible and control bar hidden

You can use the ActiveMovie Control properties to show or hide and enable or disable user interface elements of the ActiveMovie Control. The sample application includes selected menu commands that enable you to individually control each of the user interface elements. The commands on the View menu enable you to control whether the element is visible. The commands on the Enable menu enable you to control whether the element is enabled.

When the sample application loads a new file, it resets the ActiveMovie Control properties to default values and initializes the values of these selected menu commands. This fragment is from the mnu_File_Open_Click procedure:

 
   With frmViewer.ActiveMovie1 
      .EnablePositionControls = False              'Disable/Enable controls. 
      .EnableSelectionControls = False 
      .EnableTracker = False 
      .ShowPositionControls = False                'Show/don't show controls. 
      .ShowSelectionControls = False 
      .ShowTracker = True 
      mnu_Enable_PositionControls.Checked = False  'Check/uncheck menus to match 
      mnu_Enable_SelectionControls.Checked = False 'controls. 
      mnu_Enable_Tracker.Checked = False 
      mnu_View_Tracker.Checked = True 
      mnu_View_PositionControls.Checked = False 
      mnu_View_SelectionControls.Checked = False 
      ... 
   End With 

Many of the control elements have two properties associated with them: one to enable them and another to make them visible. To use the position controls, set both the EnablePositionControls and ShowPositionControls properties. The following illustration shows the display controls and all position controls with all elements of the user interface both visible and enabled.

Display form with all ActiveMovie Control elements visible and enabled

Monitoring ActiveMovie Control Events

The ActiveMovie Control automatically monitors certain events and calls event procedures accordingly. To handle one of these events, you provide only the event handling code. For example, the StateChange event indicates a change in the state of the multimedia source, such as the change from running to stopped, or the change from paused to running. To take some action when this event occurs, the application provides code as part of the control's StateChange event.

To demonstrate these event handlers, the sample application provides trivial code that increments a variable. The variable represents a count of the number of times the event has occurred. The current values for these counter variables are displayed at the bottom of the main form. The following example shows the code for the StateChange event.

 
   Private Sub ActiveMovie1_StateChange(ByVal oldState As Long, ByVal newState As Long)
 
      g_cStateChange = g_cStateChange + 1
      UpdateStatusBar 

Each event procedure passes some informational parameters too. For the StateChange event, you can determine the previous state, in addition to the control's current state, by examining the oldState and newState parameters.


Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.