Chapter 32

Extending Multimedia Capabilities Through ActiveX

by Hiro Ruo


CONTENTS

This chapter presents the multimedia capabilities that currently exist in the form of ActiveX controls and discusses how they can be used in conjunction with Visual J++.

ActiveX

Chapter 31, "Basic Java Multimedia Capabilities," investigates how multimedia content can be added to a Java applet/application using the built-in support for multimedia in the Java language and Visual J++. This is a powerful and flexible capability of Java that can greatly enhance the appeal and content of Web pages. However, there are plenty of other forms of multimedia available on the Web today.

Although Java in its original form supported multiple platforms transparently, it could not natively support the multiple formats of multimedia written in many languages. Implementing these contents still depended on having the proper application and browser extensions installed locally on the computer. If a computer were to support every content format, it would become a tangled mess of software from the many different vendors of these formats.

This problem is addressed with ActiveX extensions defined by Microsoft Corporation. ActiveX is a platform definition based on COM. (Refer to Part III, "The Foundation for Visual J++: The Component Object Model," for more information about COM.) ActiveX controls are COM objects, or a form of object linking and embedding (OLE) objects. This chapter investigates how ActiveX and Java can work hand in hand, with the help of Visual J++. (For more information about ActiveX and Microsoft's strategy for the Internet, see Chapter 19, "Extending Java Using ActiveX.")

The OLE Object Viewer

Visual J++ provides several tools and facilities to help with the integration of ActiveX controls into a Java project. One of these is the OLE Object Viewer.

The OLE Object Viewer provides a simple interface that allows the Visual J++ developer to parse the OLE objects , including ActiveX controls, that are available for implementation into a Java program. The OLE Object Viewer uses information stored in the registry of the operating system to give you a thorough understanding of all the OLE objects that are enabled in your system and the interfaces to each object. It also allows you to verify the behavior of the objects. The Object Viewer provides the following information:

The OLE Object Viewer is started by selecting OLE Object View from the Tools menu in Visual J++. Figure 32.1 shows the OLE Object View window.

Figure 32.1 : The OLE Object View window.

You can see a list of objects in the Object window on the left. Note in Figure 32.1 that the selected object is an ActiveMovie control. The registered interfaces of the object are listed in the Interface window on the bottom right. Additional information about the object is detailed in the upper-right window. The icons preceding the object name indicate the type of object; the ActiveMovie control icon indicates that it is an OLE object. Figure 32.2 is an index to the types of objects and the icons displayed in the Object Viewer.

Figure 32.2 : OLE object types.

You can use this tool and the interface information when implementing ActiveX controls to help decide which ActiveX controls can be embedded and how to integrate the object into the program.

Clicking the type definition within the Object Viewer lists the names of all the types defined for this object. Selecting one of these will display an object and all of its pertinent interface function information. Figure 32.3 illustrates the information displayed by the Type Interface Viewer for IActiveMovie. The information displayed is the function information and format for the FileName function for IActiveMovie objects.

Figure 32.3 : The Type Interface Viewer.

Selecting FileName(), as shown in Figure 32.3, illustrates the use of the function FileName in a Java program. This function is used to set the multimedia file to be played in an IActiveMovie object within a Java applet. Similarly, each function for IActiveMovie can be parsed in the Functions box, and the description viewed in the FUNCDESC box. These functions are used and implemented in an example in this chapter. The information provided by this interface will allow the correct reuse of the object selected.

The To File... button can be selected to save the object interface and function information into a text file so that it can be used as a ready reference.

As you can see, the OLE Object Viewer is a powerful tool that allows you to use existing objects and their interfaces to embed these objects into a Java program. The interfaces and functions associated with these objects can be readily looked up and used within any program.

Customizing ActiveX Controls

Another facility that Visual J++ provides is an interface to customize the objects and components of ActiveX and other COM objects: the Component Gallery.

The Component Gallery allows you to get a iconized list of available components in the system, including any programs that were written using Visual J++. ActiveX controls installed in the system are such reusable components that can be manipulated and parsed using the Component Gallery. The Component Gallery is started by selecting Component from the Insert menu. Figure 32.4 shows the Component Gallery window.

Figure 32.4 : The Component Gallery window.

The Component Gallery lists all available categories, including Microsoft-defined components, OLE controls (including ActiveX components), and separate tabs for folders containing components of previously written Visual J++ projects. Wherever available, there is also a Help button that is enabled to provide more information about the component selected.

Clicking on the Customize button will open the Customize Component Gallery dialog box. This tool provides an interface for you to create new categories, move components between categories, add components to a category, and delete components or categories. This functionality gives you flexibility to define new categories of components for reuse in future projects. Figure 32.5 illustrates the Customize Component Gallery dialog box.

Figure 32.5 : The Customize Component Gallery dialog box.

Clicking on the Properties button will display general information about the component selected. The Move option allows you to move the component selected to a different category. The Import option allows you to add an external component to the category selected.

The Java Type Library Wizard

To allow a Java program to refer to a COM object, such as an ActiveX control, Visual J++ provides the Java Type Library Wizard. This makes ActiveX controls available from any Java program. This is how multimedia content in the form of ActiveX controls can be embedded in a program developed using Visual J++.

Type libraries are defined by COM to store information, including the classes and interfaces about the COM entity. This chapter demonstrates an application in which a multimedia ActiveX control is embedded into a Java program using the Type Library Wizard in Visual J++.

First, you will create a simple applet using the Java Applet Wizard, as described in Chapter 11, "Building a Simple Java Applet with Visual J++." The template program created, AX2, will be both an applet and an application so that the Java Viewer (JVIEW) can be used. At the writing of this chapter, Visual J++ is still in beta release and does not fully support integration of all COM types. Future releases of Visual J++ will have this function enabled. Therefore, this example is a simple applet with only the addition of the ActiveX content.

After creating the starting template code, choose the Java Type Library Wizard from the Tools menu of the Microsoft Developer Studio, as shown in Figure 32.6.

Figure 32.6 : The Java Type Library Wizard.

From the Java Type Library Wizard, select the item to be implemented in the Java program-in this case, an ActiveMovie control.

When you click on OK, the output window will display the import statement that should be used to refer to the selected item and its interfaces. For this example, the import statement looks like this:


import amovie.*;

Note that the import statement is not absolutely required. Any class that must be referenced within the program can be referenced with the complete name of the class. The import statement is used to facilitate easier references using the short name.

The information provided by the Object Viewer, as described in the "OLE Object Viewer" section, can now be used to correctly utilize the functionality of this object as embedded in this example Java program.

First, a new instance of this IActiveMovie object must be defined. The following line of code is added to perform this task:


IActiveMovie AXMovie = new ActiveMovie();

Any future references to interfaces and functions associated with the ActiveMovie object can now be done through AXMovie. For this example using the ActiveMovie control, some basic settings are required. The filename of the video clip to be played must be specified by inserting the following statement:


AXMovie.putFileName("AX1.mov");

Note that calling the function FileName is performed with the prefix put. As described in the "OLE Object Viewer" section, the function is of invocation type PROPERTYPUT. This means the function is called as a sub of AXMovie, or any other name used to reference the ActiveMovie object, with a put.

In addition, the window size of the video playback is set as follows:


AXMovie.putMovieWindowSize(0);

The size settings are described by the WindowSizeConstant() type found when viewing the ActiveMovie object with the OLE Object Viewer. The parameter to the MovieWindowSize() function is a USERDEFINED parameter. The values that are accepted are as follows:

Function
Value
amvOriginalSize (int)
= 0
amvDoubleOriginalSize (int)
= 1
amvOneSixteenthScreen (int)
= 2
amvOneFourthScreen (int)
= 3
amvOneHalfScreen (int)
= 4
amvMaximized (int)
= 5

These values can be defined as constants in the Java program example. I have elected to set the value with an integer only.

You can invoke the command Run() to play back the selected video clip. This is accomplished simply by including the following statement in the program source code:


AXMovie.Run();

This is a very simple example that does not take full advantage of all the controls available with this ActiveX control. The source code in Listing 32.1 can now be compiled as a complete Java applet/application that embeds the ActiveX control ActiveMovie.


Listing 32.1. The ActiveMovie control.

import java.applet.*;

import java.awt.*;

import AX2Frame;

import amovie.*;



public class AX2 extends Applet implements Runnable

{

    Thread     m_AX2 = null;

    IActiveMovie AXMovie = new ActiveMovie();

    private Graphics m_Graphics;

    boolean m_fStandAlone = false;



    public static void main(String args[])

    {

        AX2Frame frame = new AX2Frame("AX2");

        frame.show();

                 frame.hide();

        frame.resize(frame.insets().left + frame.insets().right  + 320,

                     frame.insets().top  + frame.insets().bottom + 240);

        AX2 applet_AX2 = new AX2();

        frame.add("Center", applet_AX2);

        applet_AX2.m_fStandAlone = true;

        applet_AX2.init();

        applet_AX2.start();

            frame.show();

    }



    public AX2()

    {

    }



    public String getAppletInfo()

    {

        return "Name: AX2\r\n" +

               "Author: Hiro Yueh-Hung Ruo\r\n" +

               "Created with Microsoft Visual J++ Version 1.0";

    }





    public void init()

    {

        resize(320,240);

        AXMovie.putFileName("AX1.mov");

        AXMovie.putMovieWindowSize(0);

    }



    public void destroy()

    {

    }



    private void displayImage(Graphics g)

    {

    }



    public void paint(Graphics g)

    {

    }



    public void start()

    {

        if (m_AX2 == null)

        {

            m_AX2 = new Thread(this);

            m_AX2.start();

        }

    }



    public void stop()

    {

        if (m_AX2 != null)

        {

            m_AX2.stop();

            m_AX2 = null;

        }

    }



    public void run()

    {

            m_Graphics = getGraphics();

            MediaTracker tracker = new MediaTracker(this);

            String strImage;



            try

            {

                AXMovie.Run();

                Thread.sleep(50);

            }

            catch (InterruptedException e)

            {

                stop();

            }

    }



    public boolean mouseDown(Event evt, int x, int y)

    {

        AXMovie.Pause();

        return true;

    }

}


The resulting applet/application opens a frame and plays the selected Quicktime for Windows video clip AX1.MOV (other video formats are also supported). Again, the example uses the JVIEW.EXE real-mode Java viewer included with the Java Developer's Kit to play the video clip. Because the beta release of Visual J++ does not fully support implementation of COM objects, a browser could not be used to play back the video clip. However, the functionality of the integration of ActiveMovie can be demonstrated with JVIEW. The resulting window of the applet is shown in Figure 32.7.

Figure 32.7 : An AX2 program example with ActiveMovie.

The ActiveMovie control provides an extensive interface to control the movie content to be played back. These are not used in the example for simplicity's sake, but are shown in Listing 32.2.


Listing 32.2. ActiveMovie control functions.

QueryInterface (ByRef riid As Variant, ByRef ppvObj As Variant)

AddRef ()

Release ()

GetTypeInfoCount (ByRef pctinfo As Variant)

GetTypeInfo (ByVal itinfo As UINT, ByVal lcid As ULONG, ByRef pptinfo As Variant)

GetIDsOfNames (ByRef riid As Variant, ByRef rgszNames As Variant, 

               ByVal cNames As UINT, ByVal lcid As ULONG, 

               ByRef rgdispid As Variant)

Invoke (ByVal dispidMember As Long, ByRef riid As Variant, 

        ByVal lcid As ULONG, ByVal wFlags As USHORT, 

        ByRef pdispparams As Variant, ByRef pvarResult As Variant, 

        ByRef pexcepinfo As Variant, ByRef puArgErr As Variant)

AboutBox ()

Run ()

Pause ()

Stop ()

ImageSourceWidth ()

ImageSourceHeight ()

Author ()

Title ()

Description ()

FileName ()

FileName (ByVal  String)

Duration ()

CurrentPosition ()

CurrentPosition (ByVal  Double)

PlayCount ()

PlayCount (ByVal  Long)

SelectionStart ()

SelectionStart (ByVal  Double)

SelectionEnd ()

SelectionEnd (ByVal  Double)

CurrentState ()

Rate ()

Rate (ByVal  Double)

Volume ()

Volume (ByVal  Long)

Balance ()

Balance (ByVal  Long)

EnableContextMenu ()

EnableContextMenu (ByVal  Boolean)

ShowDisplay ()

ShowDisplay (ByVal  Boolean)

ShowControls ()

ShowControls (ByVal  Boolean)

ShowPositionControls ()

ShowPositionControls (ByVal  Boolean)

ShowSelectionControls ()

ShowSelectionControls (ByVal  Boolean)

ShowTracker ()

ShowTracker (ByVal  Boolean)

EnablePositionControls ()

EnablePositionControls (ByVal  Boolean)

EnableSelectionControls ()

EnableSelectionControls (ByVal  Boolean)

EnableTracker ()

EnableTracker (ByVal  Boolean)

AllowHideDisplay ()

AllowHideDisplay (ByVal  Boolean)

AllowHideControls ()

AllowHideControls (ByVal  Boolean)

DisplayMode ()

DisplayMode (ByVal  USERDEFINED)

AllowChangeDisplayMode ()

FilterGraph ()

FilterGraph (ByVal  LPUNKNOWN)

FilterGraphDispatch ()

DisplayForeColor ()

DisplayForeColor (ByVal  USERDEFINED)

DisplayBackColor ()

DisplayBackColor (ByVal  USERDEFINED)

MovieWindowSize (ByVal  USERDEFINED)

FullScreenMode ()

FullScreenMode (ByVal  Boolean)

AutoStart ()

AutoStart (ByVal  Boolean)

AutoRewind ()

AutoRewind (ByVal  Boolean)

hWnd ()

Appearance ()

Appearance (ByVal  USERDEFINED)

BorderStyle ()

BorderStyle (ByVal  USERDEFINED)

Enabled ()

Enabled (ByVal  Boolean)

Info ()


Note that there are several functions with duplicate names. They are actually not the same functions, however, because they are called by different methods. As previously described, FileName is called with put to set the filename of the video clip file. Calling FileName with get instead retrieves the filename of the video file being played.

These functions can be implemented in your Java program in conjunction with the ActiveMovie control to provide more flexibility and capabilities to the interface to the ActiveX content. This opens the door for truly interactive ActiveX content on a Web page using Java.

The Dialog Box Editor

Another simple method for integrating ActiveX content, or any other OLE control objects, into a Web page using Java is with the Dialog box editor provided with Visual J++. Similar to those in Visual Basic, this drag-and-drop development tool allows you to graphically determine the type and location of the controls to implement into the program.

The Dialog box editor is invoked by selecting Resources from the Insert menu item, as shown in Figure 32.8.

Figure 32.8 : Inserting resources.

Selecting Dialog in this dialog box will open the Dialog box editor of Visual J++, as shown in Figure 32.9.

Figure 32.9 : The Dialog box editor.

The default dialog box created contains two buttons: OK and Cancel. The dialog box is stretchable, allowing you to determine the size of the window to be used in the program.

To the right of the dialog box is the Control toolbox. This toolbox allows you to drag-and-drop any of a set of controls, including radio buttons, movie clips, and images, onto the dialog box's working window.

A right-click in the working area of the dialog box will bring up a menu, as illustrated in Figure 32.9. Selecting Insert OLE Control will bring up the window shown in Figure 32.10.

Figure 32.10 : The OLE Object Selector window.

A list of all available OLE control objects is displayed in a scroll box. Highlighting any of these items will display the path to the OLE control object in the PATH field at the bottom of the OLE Object Selector dialog box. In Figure 32.10, the Microsoft Internet Explorer Animated Button Object is selected. The OLE control file is IEANBTN.OCX, installed in the default Windows 95 directory.

Selecting the OK button embeds a workspace within the dialog box being developed. This will provide the infrastructure necessary to customize the ActiveX, or other OLE objects, in the Java program. The working window of the dialog box appears as shown in Figure 32.11. The working space of the selected OLE object is displayed with a text description of the object inserted.

Figure 32.11 : ActiveX object embedding.

The ActiveX object, Microsoft Internet Explorer Animated Button object, is now implemented in the dialog box being created. Note the lack of actual content of the working space of the OLE control object. This is because the object is not completely defined yet. In this example, the animated button does not have any animation or graphical content associated with it.

Following the previously listed steps allows you to use a graphical interface to easily embed any available OLE control object into a project under development. This dialog box can now be included in a Java application and enabled with some minor changes to the resulting source code.

While in the Dialog box editor, you can further customize the embedded object. Right-clicking within the workspace of the embedded object and selecting the Properties item will result in the window shown in Figure 32.12.

Figure 32.12 : ActiveX object properties.

The Object Properties window allows you to configure certain default options of the object. For the animated button example, the object ID and options relating to the display of the button on the screen are available for change. Figure 32.12 shows the default options for the animated button.

Now save the dialog box entry. Closing the working window of the Dialog Box editor in Visual J++ (or manually selecting the Save or Save As option in the File menu) will allow you to custom name the dialog box template.

Next, you must create the Java files associated with this dialog box using the Java Resource Wizard. The Java Resource Wizard (see Figure 32.13) is run by selecting Java Resource Wizard from the Tools menu.

Figure 32.13 : The Java Resource Wizard.

The Resource File created with the Dialog Box editor is entered into the File name box in Step 1 of the Java Resource Wizard. Note that the Resource File was saved in the directory of the Java project in which the dialog box will be added.

Selecting Next completes the creation of the source code for the dialog box. If a resource has a duplicate name, there will be an additional step here that allows you to rename the resource. Figure 32.14 illustrates the completion of the Java Resource Wizard.

Figure 32.14 : The dialog box created.

In the final window of the Java Resource Wizard, the files that were made as a result of creating the dialog box are listed. These files can now be implemented into a Java project to include the dialog box in the program.

The dialog box and its associated source code are implemented into the Java project as follows. First, you must select File in Project from the Insert menu. Select the IDD_DIALOG2 file to be added to the Java project.

Next, lines of code similar to those added for the previous example of implementing an ActiveMovie object must be added to this Java program. Instead of importing the amovie class, you will import the IDD_DIALOG2 class. This will allow simple references to the interfaces of the dialog box. The lines of code are as follows:


import IDD_DIALOG2;

...

IDD_DIALOG2 Abutt;

...

init() {

Abutt = new IDD_DIALOG2(this);

Because you used the Java Resource Wizard to create the IDD_DIALOG2 class, the controls associated with the dialog box can be created with the CreateControls() command, like this:


Abutt.CreateControls();

If a resize() command is included in the init() function, it must be removed.

Now add the interfaces and functions to the Microsoft Internet Explorer Animated Button to the source code within the dialog box Java files, as described in the ActiveMovie example.

Additional ActiveX Content

In addition to the ActiveMovie and Animated Button ActiveX objects, there are many more that you can use in your Java programs. These include not only those developed by Microsoft, but also a plethora of options from other companies. Table 32.1 is just a sample of such controls.

Table 32.1. ActiveX control providers.

CompanyActiveX Controls
Adobe Systems, Inc.Acrobat Control for ActiveX
Black Diamond Consulting, Inc.Surround Video
Brilliance Labs, Inc.CyberGO ActiveX Control
Citrix Systems, Inc.Citrix WinFrame ICA Control
Farallon Communications, Inc.Look@Me
MacromediaShockwave ActiveX Control
MicrosoftAnimated Button
 ActiveMovie
 Chart
 Gradient
 Label
 Marquee
 Menu
 Popup Menu
 Popup Window
 Preloader
 Stock Ticker
 Timer
 View Tracker
Vivo Software, Inc.VivoActive Player for ActiveX

In all, there are more than 1,000 ActiveX products out there at your disposal. These ActiveX controls can be used and reused to enhance the multimedia contents of the modern Web page. And with the advent of COM and its wide acceptance, ActiveX content will be accessed by almost everyone on the Web.

Summary

This chapter demonstrates how simple it can be to implement multimedia content using ActiveX. Chapter 31 demonstrates using the default Java support for video, audio, and animation to enhance the sensory impact of your Java applets/applications. However, the "old" method requires extensive creation of image content (not an easy task for those of us who are artistically impaired programmers) and coordination of video and audio to create animation.

With ActiveX as the basis for multimedia, content and interfaces can easily be reused with simple changes to the files being accessed. With COM support, these Java programs can become a de facto standard for distributing multimedia with ActiveX. It also allows developers and programmers everywhere to be able to use their own favorite language and multimedia format without worry of conflicting with the desired content of the Web page or end users' machines.

Multimedia is the defining measure for the quality of Web page content pages today, and ActiveX is the future by which multimedia content can become ubiquitous across the entire Internet.