Results 1 to 2 of 2
  1. #1
    ConvoyTh is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default Embed video on web page - Application to Applet

    Hi everyone,

    I'm new to java-forums, and newbie to java programming as well..:o

    I need to embed a video (AVI) player into a web page, and have control on that (I mean start, stop, timing and so on) but I'd like to obtain something cross browser and cross OS.. Java can do this, doesn't it??

    Well, here's the first big deal: I found this application source on the web:
    Java Code:
    import javax.media.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    
    public class AudioVideoPlayer extends JFrame
    {
      private static final String FRAME_TITLE = "Un semplice riproduttore audio/video";
      private static final String CONTROL_PANEL_TITLE = "Pannello di Controllo";
    
      // Coordinate relative alla finestra dell'applicazione
      private static final int LOC_X = 100;
      private static final int LOC_Y = 100;
      private static final int HEIGHT = 400;
      private static final int WIDTH = 400;
    
      private Player player = null;
    
    
      // Il componente di tipo JTabbedPane utilizzato per la
      // visualizzazione dei controlli associati al Player istanziato
      private JTabbedPane tabPane = null;
    
      public AudioVideoPlayer()
      {
        super(FRAME_TITLE);
        setLocation(LOC_X, LOC_Y);
        setSize(WIDTH, HEIGHT);
    
        tabPane = new JTabbedPane();
        this.getContentPane().add(tabPane);
    
        // Creazione di una classe anonima per la gestione
        // dell'evento windowCloing
        addWindowListener(new WindowAdapter()
        {
          public void windowClosing(WindowEvent e)
          {
            closePlayer();
            System.exit(0);
          }
        });
      }
    
      private JPanel createMediaPanel()
      {
        JPanel mainPnl = new JPanel();
        GridBagLayout panelLayout = new GridBagLayout();
        GridBagConstraints constr = new GridBagConstraints();
    
        mainPnl.setLayout(panelLayout);
    
        // Aggiunta del pannello ricavato dal metodo
        // getVisualComponent()
        if (player.getVisualComponent() != null)
        {   
          constr.gridx = 0;
          constr.gridy = 0;
          constr.weightx = 1;
          constr.weighty = 1;
          constr.fill = GridBagConstraints.BOTH;
          mainPnl.add(player.getVisualComponent(), constr);
        }
    
        // Aggiunta del pannello ricavato dal metodo
        // getGainControl().getControlComponent() (se esistente)
        if ((player.getGainControl() != null) &&
            (player.getGainControl().getControlComponent() != null))
        {
          constr.gridx = 1;
          constr.gridy = 0;
          constr.weightx = 0;
          constr.weighty = 1;
          constr.gridheight = 2;
          constr.fill = GridBagConstraints.VERTICAL;
          mainPnl.add(player.getGainControl().getControlComponent(), constr);
        }
    
        // Aggiunta del pannello ricavato dal metodo
        // getControlPanelComponent()
        if (player.getControlPanelComponent() != null)
        {
          constr.gridx = 0;
          constr.gridy = 1;
          constr.weightx = 1;
          constr.gridheight = 1;
    
          if (player.getVisualComponent() != null)
          {
            constr.fill = GridBagConstraints.HORIZONTAL;
            constr.weighty = 0;
          }
          else
          {
            constr.fill = GridBagConstraints.BOTH;
            constr.weighty = 1;
          }
    
          mainPnl.add(player.getControlPanelComponent(), constr);
        }
    
        return mainPnl;
      }
    
      public void setMediaLocator(MediaLocator locator) throws IOException,
            NoPlayerException, CannotRealizeException
      {
        setPlayer(Manager.createRealizedPlayer(locator));
      }
    
      public void setPlayer(Player newPlayer)
      {
        // Qualora sia presente un Player gi attivo, viene chiuso
        closePlayer();
    
        player = newPlayer;
        if (player == null) return;
    
        tabPane.removeAll();
        tabPane.add(CONTROL_PANEL_TITLE, createMediaPanel());
        Control[] controls = player.getControls();
        for (int i = 0; i < controls.length; i++)
        {
          if (controls[i].getControlComponent() != null)
          {
            tabPane.add(controls[i].getControlComponent());
          }
        }
      }
    
      private void closePlayer()
      {
        if (player != null)
        {
          player.stop();
          player.close();
        }
      }
    
      public static void main(String[] args)
      {
        try
        {
          if (args.length == 1)
          {
            AudioVideoPlayer mpf = new AudioVideoPlayer();
    
            mpf.setMediaLocator(new MediaLocator(new File(args[0]).toURL()));
            mpf.setVisible(true);
          }
          else
          {
            System.out.println("E' necessario fornire in input il nome del " +
                  "file da riprodurre");
          }
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    }
    It uses jmf, and it works..
    But I'm definitely not able to convert that into an Applet..:(

    Can anyone help me?

    Thank you!
    Last edited by ConvoyTh; 11-24-2008 at 05:21 PM.

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Panels and JFrames can be added to applets, or at least a JFrame can be added to the Applet.getContentPane()

    You have JFrame and the Player all in the same code, I could dis-entangle it but you should do the work.

    Study MVC - Model, View, Controller. Make the JFrame the view, the "player" the Model and an applet the controller.

    Probably start by writing class Player, add it to a ....

    Uh, study MVC - post back.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. Have to embed link to website in JFrame
    By pkumar85 in forum New To Java
    Replies: 0
    Last Post: 11-24-2008, 12:01 AM
  2. Help, Embed video in java applet?
    By darthbane13 in forum New To Java
    Replies: 0
    Last Post: 08-29-2008, 10:09 PM
  3. How to embed Swing and AWT in SWT
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-02-2008, 08:07 PM
  4. How Do I Embed Java Correctly To A Web Page
    By abcd in forum Java Applets
    Replies: 7
    Last Post: 01-28-2008, 07:53 AM
  5. Email Embed Image
    By gui.gomes in forum Advanced Java
    Replies: 3
    Last Post: 11-19-2007, 02:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •