播放媒体对象3 : 媒体 « 图形用户界面 « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » 图形用户界面 » 媒体屏幕截图 
播放媒体对象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媒体:查找组件Java媒体:查找组件
2. 查询配置JMF查询配置JMF
3. Show the Location2Location class in actionShow the Location2Location class in action
4. 捕获音频或视频通过设备连接到PC
5. Choose the media they wish to playChoose the media they wish to play
6. 做音频捕捉
7. 统计信息跟踪构成一个媒体对象
8. 播放媒体对象
9. 播放器:播放媒体对象
10. 列出所有撷取装置目前已知的JMF列出所有撷取装置目前已知的JMF
11. 传输媒体从一个位置到另一个位置
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.