Select a media file from tjelocal file system and gain statistics : JMF « 2D Graphics GUI « Java

Home
Java
1.2D Graphics GUI
2.2D Graphics GUI1
3.3D
4.Advanced Graphics
5.Ant
6.Apache Common
7.Chart
8.Class
9.Collections Data Structure
10.Data Type
11.Database SQL JDBC
12.Design Pattern
13.Development Class
14.EJB3
15.Email
16.Event
17.File Input Output
18.Game
19.Generics
20.GWT
21.Hibernate
22.I18N
23.J2EE
24.J2ME
25.JDK 6
26.JNDI LDAP
27.JPA
28.JSP
29.JSTL
30.Language Basics
31.Network Protocol
32.PDF RTF
33.Reflection
34.Regular Expressions
35.Scripting
36.Security
37.Servlets
38.Spring
39.Swing Components
40.Swing JFC
41.SWT JFace Eclipse
42.Threads
43.Tiny Application
44.Velocity
45.Web Services SOA
46.XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
SCJP
Java » 2D Graphics GUI » JMFScreenshots 
Select a media file from tjelocal file system and gain statistics
  

/**********************************************************************
* GUIMediaStatistics - a GUI allowing the user to select a media
* file from tjelocal file system and gain statistics on that media
* (audio or video) concerning its tracks and their format/composition.
*
* The class is built atop the MediaStatistics class and arguably
* provides a more user friendly mechanism for determining the
*format of media.
*
@author Spike Barlow
***********************************************************************/

import java.awt.*;
import java.awt.event.*;
import javax.media.*;
import java.util.*;
public class GUIMediaStatistics extends Frame implements ActionListener {

  /** Object to determine the format ofthe media. Performs all the real work. */
  protected MediaStatistics     stats;

  /** User wants to search for a file. */
  protected Button              browseButton;

  /** User wants to know the format of the current file. */
  protected Button              getStatsButton;

  /** Current state of processing. */
  protected int                 state;

  /** Where the format informationis displayed. */
  protected TextArea            results;

  /** Area i which the user can type the name of a file. */
  protected TextField           mediaField;

  /** Pause in milliseconds between checks to see if format is known. */
  public static final int       PAUSE = 50;

  /** Maximum wait before giving up on determining theformat. */
  public static final int       MAX_WAIT_PERIOD = 10000;

  /** Directory that the user last searched for files. */
  protected String              lastDirectory;





/**********************************************************************
* Construct the GUIMediaStatistics object, constructing the various
* components and laying them out on the screen.
**********************************************************************/
public GUIMediaStatistics() {
  super("GUIMediaStatistics");
  setLayout(new BorderLayout());

  addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
      System.exit(0)} });

  Panel filePanel = new Panel();

  filePanel.add(new Label("File:"));
  mediaField = new TextField(40);
  filePanel.add(mediaField);

  browseButton =new Button("browse...");
  filePanel.add(browseButton);
  browseButton.addActionListener(this);

  getStatsButton = new Button("get stats...");
  filePanel.add(getStatsButton);
  getStatsButton.addActionListener(this);

  add(filePanel,"North");

  results = new TextArea(80,10);
  results.setEditable(false);
  add(results,"Center");
}


/************************************************************************
* Respond to user button presses - either browsing for a file or
* gathering format info on the current file.
************************************************************************/
public void actionPerformed(ActionEvent e) {

    /////////////////////////////////
    // Browse - use FileDialog class.
    /////////////////////////////////
    if (e.getSource() == browseButton) {
      FileDialog choice = new FileDialog(this, "Media File Choice",
          FileDialog.LOAD);
      if (lastDirectory != null)
        choice.setDirectory(lastDirectory);
      choice.show();
      String selection = choice.getFile();
      if (selection != null) {
        lastDirectory = choice.getDirectory();
        mediaField.setText("file://" + choice.getDirectory()
            + selection);
      }
    }
    ////////////////////////////////////////////////////////
    // Get statistics - create a MediaStatistics object and
    // monitor its progress.
    ///////////////////////////////////////////////////////
    else {
      stats = new MediaStatistics(mediaField.getText());
      monitorAndReport();
    }
  }

  /************************************************************************
   * Monitor the progress of the MediaStatistics object as it attempts to
   * determineformatinformation for the current file. It periodically
   * polls the object, obtaining a report from it and printing it to the
   * screen. The polling stops as soon as the format is known, it is
   * found that it isimpossible to determine a format, or a certain time
   * period is exceeded.
   **************************************************************************/
  private void monitorAndReport() {
    int elapsed = 0;

    state = stats.getState();
    while (elapsed < MAX_WAIT_PERIOD
        && (state != MediaStatistics.FAILED && state != MediaStatistics.KNOWN)) {
      results.setText(stats.getReport());
      try {
        Thread.sleep(PAUSE);
      catch (Exception e) {
      }
      elapsed += PAUSE;
      state = stats.getState();
    }
    if (state == MediaStatistics.FAILED || state == MediaStatistics.KNOWN)
      results.setText(stats.getReport());
    else
      results.setText("Timing out after maximum period of "
          + MAX_WAIT_PERIOD + "ms");
  }

  /***************************************************************************
   * Main method - construct a GUIMediaStatistics frame and show it on the
   * screen.
   **************************************************************************/
  public static void main(String[] args) {

    GUIMediaStatistics gui = new GUIMediaStatistics();
    gui.pack();
    gui.setSize(600400);
    gui.show();
  }
}

           
         
    
  
Related examples in the same category
1.Query the installed version of the JMFQuery the installed version of the JMF
2.Renderer for RGB images using AWT Image using Java Media API
3.A motion detection algoritm for use with the Java Media Framework API (JMF).
4.javax.media
5.Media player
6.Sample program to demonstrate FramePositioningControl.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.