Select a media file from tjelocal file system and gain statistics : JMF « 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 » 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
w___w__w__.j_ava___2___s_.___c__om__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.