JMF usage question

Discussion in 'Java' started by Ted Holden, Nov 3, 2004.

  1. Ted Holden

    Ted Holden Guest

    I've ended up with a situation which positively requires Java, which I
    have very little experience with, and am basically trying to have one
    or more other controls in a browser applet which uses the java media
    player and JMF. I've tried to simply add a TextArea widget next to
    the media player in one of the standard examples they provide, but all
    that comes up is the media player. I'd appreciate it if anybody could
    tell me what I'm doing wrong here:





    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.String;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.io.IOException;
    import java.util.Properties;
    import javax.media.*;
    import java.awt.TextArea;



    public class SimplePlayerApplet extends Applet implements
    ControllerListener {

    // media Player
    Player player = null;
    // component in which video is playing
    Component visualComponent = null;
    // controls gain, position, start, stop
    Component controlComponent = null;
    // displays progress during download
    Component progressBar = null;
    boolean firstTime = true;
    long CachingSize = 0L;
    Panel panel1 = null;
    TextArea textarea1 = null;
    int controlPanelHeight = 0;
    int videoWidth = 0;
    int videoHeight = 0;

    public SimplePlayerApplet() {
    super();
    init();
    }

    public void init() {
    //$ System.out.println("Applet.init() is called");
    setLayout(null);
    this.setSize(900, 900);
    setBackground(Color.white);

    panel1 = new Panel();
    panel1.setLayout( null );
    add(panel1);
    panel1.setBounds(0, 0, 350, 350);


    textarea1 = new TextArea();
    add(textarea1);
    textarea1.setBounds(500,0,150,150);






    // input file name from html param
    String mediaFile = null;
    // URL for our media file
    MediaLocator mrl = null;
    URL url = null;

    // Get the media filename info.
    // The applet tag should contain the path to the
    // source media file, relative to the html page.

    if ((mediaFile = getParameter("FILE")) == null)
    Fatal("Invalid media file parameter");

    try {
    url = new URL(getDocumentBase(), mediaFile);
    mediaFile = url.toExternalForm();
    } catch (MalformedURLException mue) {
    }

    try {
    // Create a media locator from the file name
    if ((mrl = new MediaLocator(mediaFile)) == null)
    Fatal("Can't build URL for " + mediaFile);

    try {
    player = Manager.createPlayer(mrl);
    } catch (NoPlayerException e) {
    System.out.println(e);
    Fatal("Could not create player for " + mrl);
    }


    // Add ourselves as a listener for a player's events
    // player.addControllerListener(this);

    } catch (MalformedURLException e) {
    Fatal("Invalid media file URL!");
    } catch (IOException e) {
    Fatal("IO exception creating player for " + mrl);
    }


    }



    public void start() {
    //$ System.out.println("Applet.start() is called");
    // Call start() to prefetch and start the player.
    if (player != null) player.start();
    }

    /**
    * Stop media file playback and release resource before
    * leaving the page.
    */
    public void stop() {
    //$ System.out.println("Applet.stop() is called");
    if (player != null) {
    player.stop();
    player.deallocate();
    }
    }

    public void destroy() {
    //$ System.out.println("Applet.destroy() is called");
    player.close();
    }


    /**
    * This controllerUpdate function must be defined in order to
    * implement a ControllerListener interface. This
    * function will be called whenever there is a media event
    */
    public synchronized void controllerUpdate(ControllerEvent event) {
    // If we're getting messages from a dead player,
    // just leave
    if (player == null)
    return;

    // When the player is Realized, get the visual
    // and control components and add them to the Applet
    if (event instanceof RealizeCompleteEvent) {
    // if (progressBar != null) {
    // panel1.remove(progressBar);
    // progressBar = null;
    // }

    int width = 320;
    int height = 0;
    if (controlComponent == null)
    if (( controlComponent =
    player.getControlPanelComponent()) != null) {

    controlPanelHeight =
    controlComponent.getPreferredSize().height;
    panel1.add(controlComponent);
    height += controlPanelHeight;
    }
    if (visualComponent == null)
    if (( visualComponent =
    player.getVisualComponent())!= null) {
    panel1.add(visualComponent);
    Dimension videoSize =
    visualComponent.getPreferredSize();
    videoWidth = videoSize.width;
    videoHeight = videoSize.height;
    width = videoWidth;
    height += videoHeight;
    visualComponent.setBounds(0, 0, videoWidth,
    videoHeight);
    }

    panel1.setBounds(0, 0, width, height);
    if (controlComponent != null) {
    controlComponent.setBounds(0, videoHeight,
    width, controlPanelHeight);
    controlComponent.invalidate();
    }


    } else if (event instanceof CachingControlEvent) {
    if (player.getState() > Controller.Realizing)
    return;
    // Put a progress bar up when downloading starts,
    // take it down when downloading ends.
    CachingControlEvent e = (CachingControlEvent) event;
    CachingControl cc = e.getCachingControl();

    // Add the bar if not already there ...
    if (progressBar == null) {
    if ((progressBar = cc.getControlComponent()) != null)
    {
    panel1.add(progressBar);
    panel1.setSize(progressBar.getPreferredSize());
    validate();
    }
    }
    } else if (event instanceof EndOfMediaEvent) {
    // We've reached the end of the media; rewind and
    // start over
    player.setMediaTime(new Time(0));
    player.start();
    } else if (event instanceof ControllerErrorEvent) {
    // Tell TypicalPlayerApplet.start() to call it a day
    player = null;
    Fatal(((ControllerErrorEvent)event).getMessage());
    } else if (event instanceof ControllerClosedEvent) {
    panel1.removeAll();
    }
    }

    void Fatal (String s) {
    // Applications will make various choices about what
    // to do here. We print a message
    System.err.println("FATAL ERROR: " + s);
    throw new Error(s); // Invoke the uncaught exception
    // handler System.exit() is another
    // choice.

    }


    }
     
    Ted Holden, Nov 3, 2004
    #1
    1. Advertising

  2. On Wed, 03 Nov 2004 21:12:40 GMT, Ted Holden wrote:

    > I've ended up with a situation which positively requires Java,


    If that requirement is 'x-plat', you may get some nasty
    surprises when using JMF. Some of it is not (x-plat).

    >..which I
    > have very little experience with,


    Best group for (generally) Java beginners is described here
    <http://www.physci.org/codes/javafaq.jsp#cljh>

    >..and am basically trying to have one
    > or more other controls in a browser applet which uses the java media
    > player and JMF.


    You provided an example, but your example also requires JMF
    (which is secondary to this lay out problem), and I was not able
    to compile it.

    >..I've tried to simply add a TextArea widget next to
    > the media player in one of the standard examples they provide, but all
    > that comes up is the media player.


    You should substitute the player for something simple like a button
    while you sort the lay out problem.

    >..I'd appreciate it if anybody could
    > tell me what I'm doing wrong here:


    For the reasons above, not immediately, but I will
    offer some tips on preparing examples..
    <http://www.physci.org/codes/sscce.jsp>

    And the Sun lay out tutorial...
    <http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html>

    If you cannot solve the problem by doing the latter,
    have a close look over the document on preparing examples.
    You should be able to provide a simpler statement of the
    lay out problem, and probably in less that 50 lines of code
    (as opposed to over 200).

    HTH

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
     
    Andrew Thompson, Nov 4, 2004
    #2
    1. Advertising

  3. Ted Holden

    Ted Holden Guest

    On Thu, 04 Nov 2004 02:40:06 GMT, Andrew Thompson
    <> wrote:

    >On Wed, 03 Nov 2004 21:12:40 GMT, Ted Holden wrote:
    >
    >> I've ended up with a situation which positively requires Java,

    >
    >If that requirement is 'x-plat', you may get some nasty
    >surprises when using JMF. Some of it is not (x-plat).



    What exactly is x-plat?

    Basically, all I need is somethinng which works and is reasonably
    portable and JMF appears to satisfy that, IF I can get it to work with
    other widgets on the screen at the same time. I'm still looking at
    different ways of trying to do that but haven't succeeded at it so
    far.

    The only other approach I've seen to this sort of problem would
    involve JavaScript and either separate Java applets or a Java applet
    and the windows media player, but I can't assume all users will be
    using windows.
     
    Ted Holden, Nov 4, 2004
    #3
  4. On Thu, 04 Nov 2004 17:25:22 GMT, Ted Holden wrote:

    > On Thu, 04 Nov 2004 02:40:06 GMT, Andrew Thompson
    > <> wrote:
    >
    >>On Wed, 03 Nov 2004 21:12:40 GMT, Ted Holden wrote:
    >>
    >>> I've ended up with a situation which positively requires Java,

    >>
    >>If that requirement is 'x-plat', you may get some nasty
    >>surprises when using JMF. Some of it is not (x-plat).

    >
    >
    > What exactly is x-plat?


    Cross platform, or..

    > Basically, all I need is somethinng which works and is reasonably
    > portable


    'portable' across platforms. It depends on the media types
    (which you have thus far not specified).

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
     
    Andrew Thompson, Nov 4, 2004
    #4
  5. Ted Holden

    Ted Holden Guest


    >
    >Cross platform, or..
    >
    >> Basically, all I need is somethinng which works and is reasonably
    >> portable

    >
    >'portable' across platforms. It depends on the media types
    >(which you have thus far not specified).


    Basically just mpeg movie files, mpeg2 and possibly mpeg4 and for a
    general purpose product if it oculd work on Windows and Apple machines
    that would probably suffice, with Linux nice to have also.

    Any reason not to think JMF would do that, or is there any other
    possible way to go at the problem if it doesn't?
     
    Ted Holden, Nov 6, 2004
    #5
  6. On Sat, 06 Nov 2004 01:49:46 GMT, Ted Holden wrote:

    (JMF)
    >>Cross platform, or..
    >>
    >>> Basically, all I need is somethinng which works and is reasonably
    >>> portable

    >>
    >>'portable' across platforms. It depends on the media types
    >>(which you have thus far not specified).

    >
    > Basically just mpeg movie files, mpeg2 and possibly mpeg4


    <http://java.sun.com/products/java-media/jmf/2.1.1/formats.html>

    >..and for a
    > general purpose product if it oculd work on Windows and Apple machines
    > that would probably suffice, with Linux nice to have also.
    >
    > Any reason not to think JMF would do that,


    You'd need to consult the document above and perhaps
    run some simple examples.

    >..or is there any other
    > possible way to go at the problem if it doesn't?


    I'm no expert in video media, sorry.

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
     
    Andrew Thompson, Nov 6, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. metfan
    Replies:
    2
    Views:
    4,853
    Robert Olofsson
    Oct 21, 2003
  2. ted holden

    Eclipse, Visual Editor, JMF usage

    ted holden, Oct 25, 2004, in forum: Java
    Replies:
    0
    Views:
    524
    ted holden
    Oct 25, 2004
  3. Replies:
    1
    Views:
    755
    Andrew Thompson
    Jul 20, 2006
  4. Colin J. Williams

    Webchecker Usage - a problem with local usage

    Colin J. Williams, Feb 25, 2004, in forum: Python
    Replies:
    1
    Views:
    543
    Colin J. Williams
    Feb 26, 2004
  5. Replies:
    0
    Views:
    2,344
Loading...

Share This Page