Sample Applet: Using the JMF MultiPlayer Bean


Introduction

The MultiPlayerApplet sample demonstrates some of the features of the JMF MultiPlayer Bean. It shows how to set the JMF MultiPlayer Bean properties and how to start and stop the instance of JMF MultiPlayer bean when the applet starts and stops. The applet shows two buttons, each representing one player.  To limit the size of the zip, the same media clip is used for both buttons, but two different players are created and they operate independently.

Running the Sample Applet

If you have the correct browser configuration,  the sample applet is running below.  If it is not running check that:

Netscape 4.05:   For Netscape browsers, Netscape security limits the capabilities of running local applets.  To run JMFPlayer applets using Netscape Communicator 4.05,  you must add the following three lines to Netscape\Users\Default\prefs.js:

user_pref("signed.applets.codebase_principal_support",true);
user_pref("signed.applets.local_classes_have_30_powers", true);
user_pref("signed.applets.low_security_for_local_classes", true);

Netscape Communicator 4.06 and above: Netscape security exceptions occur when running local applets that read from the local hard drive.  Applets have to be run remotely,  through a web server.

Internet Explorer 4.0: To run the sample applet locally with JMF 1.1 for Web Servers or Cross-platform java version, make sure that the jmf.jar, JMFPlayer.jar, and mplite.jar are in the system's classpath.

                                   

The Source Code

The following is the source code of the sample applet:

/*
        A basic extension of the java.applet.Applet class
 */

import java.awt.*;
import java.applet.*;

import com.ibm.jmf.MultiPlayer.MultiPlayerBean;

public class MultiPlayerSampleApplet extends Applet
{
  public void init()
  {
    setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
    setSize(300,400);
    setBackground(new Color(12632256));

    //instantiate the bean
    multiPlayerBean1 = new com.ibm.jmf.MultiPlayer.MultiPlayerBean();

    //set the Media Groups
    multiPlayerBean1.setMediaNamesString("ibm_magic_8.mov,ibm_magic_8.gif,ibm_magic_8.mov,ibm_magic_8.gif",this);

    //set the Related Links
    multiPlayerBean1.setLinksString("1,http://www.software.ibm.com/net.media,0,0,2,http://java.sun.com/products/java-media/jmf/index.html,0,0");
    multiPlayerBean1.setBounds(0,5,300,400);
    add(multiPlayerBean1);
  }

  public void stop()
  {
    if (multiPlayerBean1 != null)
      multiPlayerBean1.stop();
  }

  public void destroy()
  {
    if (multiPlayerBean1 != null)
      multiPlayerBean1.destroy();
  }        

  //{{DECLARE_CONTROLS
  com.ibm.jmf.MultiPlayer.MultiPlayerBean multiPlayerBean1;
  //}}
}