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 / February 2006

Tip: Looking for answers? Try searching our database.

java help

Thread view: 
ben.jenson@gmail.com - 23 Feb 2006 22:02 GMT
hi im quite a newbie at java and wondered if anyone could help, i want
to create a simple media player with stop and play buttons which
display the avi in the centre, when u click play it says "wheres the
file" u find it and it plays central in the screen.
im using the swing classes to do my gui buttons but how can i cross
reference to say use javax media or something, could i call a controll
listener to play the avi files
can some pro please come along and save me, would be willing to pay
for tutorials or help :)
Knute Johnson - 23 Feb 2006 22:50 GMT
> hi im quite a newbie at java and wondered if anyone could help, i want
> to create a simple media player with stop and play buttons which
[quoted text clipped - 5 lines]
>  can some pro please come along and save me, would be willing to pay
> for tutorials or help :)

Ben:

You will need Java Media Framework, JMF and you can get it at:

http://java.sun.com/products/java-media/jmf/index.jsp

Below is the test program I use to check my installation and video
files.  You should be able to piece together your program from this
outline.  You will also need to not use Swing.  The components available
in JMF are AWT not Swing.

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

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

public class VideoPlayer extends Frame {
    Player player;

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

        setLayout(new BorderLayout());

        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 = (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");

                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]);
            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/

ben.jenson@gmail.com - 27 Feb 2006 18:05 GMT
knute u r a star :) thanks


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.