Play the media object 3 : Media « 2D Graphics GUI « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » 2D Graphics GUI » MediaScreenshots 
Play the media object 3

/*

Java Media APIs: Cross-Platform Imaging, Media and Visualization
Alejandro Terrazas
Sams, Published November 2002, 
ISBN 0672320940
*/

/*******************************************************************************
 * A "Bare Bones" Player Applet (BBP Applet) that will play the media object
 * indicated in the "media2Play" property of the Applet tag.
 
 * <p>
 * The applet demonstrates the relative ease with which the JMF can be employed,
 * particularly for playing. The applet a minimal player, placing the controls
 * for the player and the visual component for the played object within the
 * Applet. The object plays once, but can be controlled by the user through the
 * control panel provided.
 
 * <p>
 * The tag for the Applet should look something like:
 
 * <!-- Sample HTML <applet code="BBPApplet.class" width=300 height=400> <param
 * name="media2Play" value="myVideo.mpg"> </applet> -->
 
 @author Spike Barlow
 ******************************************************************************/

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
import javax.media.*;
import javax.media.control.*;

public class ControlQueryPApplet extends Applet implements ControllerListener {

  /***************************************************************************
   * Object to play the media. Only attribute that the Applet really needs.
   **************************************************************************/
  protected Player player;

  /***************************************************************************
   * The name of the media to be played.
   **************************************************************************/
  protected String nameOfMedia2Play;

  /***************************************************************************
   * Name of the Property field within the applet tage indicating the name of
   * the media to play.
   **************************************************************************/
  private static final String MEDIA_NAME_PROPERTY = "media2Play";

  /***************************************************************************
   * Object describing the location of the media to be played.
   **************************************************************************/
  protected MediaLocator locator;

  protected SystemTimeBase timer;

  /***************************************************************************
   * Initialise the applet by attempting to create and start a Player object
   * capable of playing the media specified in the applet tag.
   **************************************************************************/
  public void init() {

    setLayout(new BorderLayout());
    setBackground(Color.lightGray);
    try {
      nameOfMedia2Play = (new URL(getDocumentBase(),
          getParameter(MEDIA_NAME_PROPERTY))).toExternalForm();
      locator = new MediaLocator(nameOfMedia2Play);
      Manager.setHint(Manager.PLUGIN_PLAYER, new Boolean(true));
      player = Manager.createPlayer(locator);
      player.addControllerListener(this);
      timer = new SystemTimeBase();
      player.start();
    catch (Exception e) {
      throw new Error("Couldn't initialise BBPApplet: " + e.getMessage());
    }
  }

  /***************************************************************************
   * Respond to ControllerEvents from the Player that was created. For the
   * bare bones player the only event of import is the RealizeCompleteEvent.
   * At that stage the visual component and controller for the Player can
   * finally be obtained and thus displayed.
   **************************************************************************/
  public synchronized void controllerUpdate(ControllerEvent e) {

    if (instanceof RealizeCompleteEvent) {
      Control[] allControls = player.getControls();
      System.out.println("" + allControls.length
          " controls for a Player @ REALIZED:");
      for (int i = 0; i < allControls.length; i++)
        System.out.println("" (i + 1": " + allControls[i]);
      add(player.getVisualComponent()"North");
      add(player.getControlPanelComponent()"South");
      validate();
    else if (instanceof StartEvent) {
      Control[] allControls = player.getControls();
      System.out.println("" + allControls.length
          " controls for a Player @ START:");
      Panel panel = new Panel();
      for (int i = 0; i < allControls.length; i++) {
        System.out.println("" (i + 1": " + allControls[i]);
        Component cont = allControls[i].getControlComponent();
        if (cont != null) {
          System.out.println("Has a graphical component");
          panel.add(cont);
        }
      }
      panel.validate();
      add(panel, "Center");
      validate();
      FrameGrabbingControl frameControl = (FrameGrabbingControlplayer
          .getControl("javax.media.control.FrameGrabbingControl");
      if (frameControl == null)
        System.out.println("Unable to obtain FrameRateControl");
      else {
        System.out.println("Have Frame Rate control");
        panel.add(frameControl.getControlComponent());
        panel.validate();
      }

    }

  }

}
           
       
Related examples in the same category
1. Java Media: Find ComponentsJava Media: Find Components
2. Query the manager class about the configuration and support of JMFQuery the manager class about the configuration and support of JMF
3. Show the Location2Location class in actionShow the Location2Location class in action
4. Capture audio or video through devices connected to the PC
5. Choose the media they wish to playChoose the media they wish to play
6. Do Audio Capture
7. Statistics about the tracks that compose a media object
8. Play the media object
9. A Bare Bones Player: play the media object
10. List all capture devices currently known to the JMFList all capture devices currently known to the JMF
11. Transfer media from one location to another carrying out the specified
ww___w.__ja___va_2s.__c___o_m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.