Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / August 2006

Tip: Looking for answers? Try searching our database.

help with getting my movie in

Thread view: 
ben.jenson@gmail.com - 12 Aug 2006 17:13 GMT
ive created a simple gui and want to input an mpeg file but carnt get
it working, can anyone help me rearrange my code or explain how to do
it or what the prob is many thanks i have been tryin alsorts so i ts a
bit of a mess lol :P

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.*;
import java.net.*;

public class KD1 extends JFrame
{
 public KD1() throws Exception
 {
  URL iliketheway = null;
  Player myPlayer = null;
   //iliketheway = new URL( "D:\\Documents and Settings\\ben\\My
Documents\\Modelworks\\MyProjects\\I Like The Way.mpg" );
   //myPlayer = Manager.createPlayer(iliketheway);

  myPlayer = Manager.createPlayer( new MediaLocator( "D:\\Documents
and Settings\\ben\My Documents\\Modelworks\\MyProjects\\I Like The
Way.mpg" ));
  Component myVisual = null;
  Component myControls = null;
  JPanel visualPanel = null;

  myVisual = myPlayer.getVisualComponent();

  if (myVisual != null)
  {
    visualPanel = new JPanel();
    visualPanel.setLayout(new FlowLayout());
    visualPanel.add(myVisual);

    myControls = myPlayer.getControlPanelComponent();

    if (myControls != null)
    {

    }
  }

  getContentPane().setLayout(new BorderLayout() );

  JPanel t = new JPanel(new BorderLayout());

  ImageIcon icon = new ImageIcon("H:\\PROJECT\\TRANSITION.JPG") ;

  JButton transition = new JButton(icon);

  JButton play = new JButton("PLAY");
  play.addActionListener(
   new ActionListener() {
       public void actionPerformed(ActionEvent e) {
         System.out.println( "start playing" );
       }
   }
);
  JButton stop = new JButton("STOP");
  stop.addActionListener(
   new ActionListener() {
       public void actionPerformed(ActionEvent e) {
         System.out.println( "stop playing" );
       }
   }
);

  JLabel title = new JLabel("karaokedrive version 1", JLabel.CENTER);

  getContentPane().setBackground(Color.yellow);
  getContentPane().add(title, BorderLayout.NORTH );
  getContentPane().add(t, BorderLayout.CENTER );
  t.add(transition, BorderLayout.CENTER);
  getContentPane().add(play, BorderLayout.SOUTH );
  getContentPane().add(stop, BorderLayout.SOUTH );
  getContentPane().add(visualPanel, BorderLayout.CENTER );
  getContentPane().add(myControls, BorderLayout.SOUTH );
// start
   addWindowListener(
    new WindowAdapter()
    {
     public void windowClosing( WindowEvent we )
     {
       System.out.println( "i will not quit" );

     }
    }
   );
   // end of window listener bit

 }

 public static void main( String Args[] )throws Exception
 {
   KD1 myFrame = new KD1();
   int width = 700;
   int height = 500;
   myFrame.setSize(width, height);
   myFrame.setVisible( true );
 }

}
Knute Johnson - 16 Aug 2006 23:17 GMT
> ive created a simple gui and want to input an mpeg file but carnt get
> it working, can anyone help me rearrange my code or explain how to do
[quoted text clipped - 100 lines]
>
> }

This program will let you know what is happening when you try to play
your file.  If it works in here you should be able to get it to work in
your program.

knute...

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import java.util.*;

import javax.imageio.*;
import javax.media.*;
import javax.media.control.*;
import javax.media.format.*;
import javax.media.util.*;

public class VideoPlayer extends Frame {
    Player player;
    FormatControl formatControl;
    FrameGrabbingControl grabber;

    public VideoPlayer(String[] args) {
        super("Video Player");

        setLayout(new BorderLayout());

        MenuBar mb = new MenuBar();
        setMenuBar(mb);

        Menu mfile = new Menu("File");
        mb.add(mfile);

        final MenuItem mi = new MenuItem("Grab");
        mfile.add(mi);
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                Buffer buf = grabber.grabFrame();
                BufferToImage b2i =
                 new BufferToImage((VideoFormat)buf.getFormat());
                BufferedImage bi = (BufferedImage)b2i.createImage(buf);
                if (bi != null) {
                    try {
                        ImageIO.write(bi,"JPEG",new File("image.jpg"));
                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                    }
                }
            }
        });

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                if (player != null) {
                    player.stop();
                    player.close();
                    System.exit(0);
                }
            }
        });

        ControllerListener cl = new ControllerAdapter() {
            public void configureComplete(ConfigureCompleteEvent cce) {
                System.out.println("configure complete event");
            }
            public void controllerError(ControllerErrorEvent cee) {
                System.out.println("controller error event");
            }
            public void controllerClosed(ControllerClosedEvent cce) {
                System.out.println("controller closed event");
                System.exit(0);
            }
            public void deallocate(DeallocateEvent de) {
                System.out.println("deallocate event");
            }
            public void endOfMedia(EndOfMediaEvent eome) {
                System.out.println("end of media event");
            }
            public void formatChange(FormatChangeEvent fce) {
                System.out.println("format change event");
                pack();
            }
            public void internalError(InternalErrorEvent iee) {
                System.out.println("internal error");
            }
            public void mediaTimeSet(MediaTimeSetEvent mtse) {
                System.out.println("media time set event");
            }
            public void prefetchComplete(PrefetchCompleteEvent pce) {
                System.out.println("prefetch complete event");
            }
            public void realizeComplete(RealizeCompleteEvent rce) {
                System.out.println("realize complete event");

                Component c = player.getVisualComponent();
                if (c != null)
                    add(c,BorderLayout.CENTER);
                else
                    System.out.println("no visual component");

                c = player.getControlPanelComponent();
                if (c != null)
                    add(c,BorderLayout.SOUTH);

                formatControl = (FormatControl)
                 player.getControl("javax.media.control.FormatControl");

                if (formatControl != null) {
                    c = formatControl.getControlComponent();
                    if (c != null)
                        add(c,BorderLayout.EAST);
                    else
                        System.out.println("no format control component");
                } else
                    System.out.println("no format control");

                grabber = (FrameGrabbingControl)player.getControl(
                 "javax.media.control.FrameGrabbingControl");
                if (grabber == null)
                    mi.setEnabled(false);

                pack();
                setVisible(true);
            }
            public void restarting(RestartingEvent re) {
                System.out.println("restarting event");
            }
            public void sizeChange(SizeChangeEvent sce) {
                System.out.println("size change event");
            }
            public void start(StartEvent se) {
                System.out.println("start event");
            }
            public void stop(StopEvent se) {
                System.out.println("stop event");
            }
            public void transition(TransitionEvent te) {
                System.out.println("transition event");
                int state = te.getCurrentState();
                switch (state) {
                    case Processor.Configuring:
                        System.out.println("  configuring");
                        break;
                    case Processor.Configured:
                        System.out.println("  configured");
                        break;
                    case Processor.Prefetching:
                        System.out.println("  prefetching");
                        break;
                    case Processor.Prefetched:
                        System.out.println("  prefetched");
                        break;
                    case Processor.Realizing:
                        System.out.println("  realizing");
                        break;
                    case Processor.Realized:
                        System.out.println("  realized");
                        break;
                    case Processor.Unrealized:
                        System.out.println("  unrealized");
                        break;
                    case Processor.Started:
                        System.out.println("  started");
                        break;
                }
            }
        };
        try {
            MediaLocator ml;
            File file = new File(args[0]);
            if (file.exists()) {
                ml = new MediaLocator(file.toURL());
            } else
                ml = new MediaLocator(args[0]);
            Manager.setHint(Manager.PLUGIN_PLAYER,Boolean.TRUE);
            player = Manager.createPlayer(ml);
            player.addControllerListener(cl);
            player.prefetch();
        } catch (NoPlayerException npe) {
            System.out.println(npe);
            System.exit(0);
        } catch (IOException ioe) {
            System.out.println(ioe);
            System.exit(0);
        }
    }

    public static void main(String[] args) {
        new VideoPlayer(args);
    }
}

Signature

Knute Johnson
email s/nospam/knute/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.