For Programmers: Free Programming Magazines  


Home > Archive > Java Help > February 2006 > java help









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author java help
ben.jenson@gmail.com

2006-02-23, 7:03 pm

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

2006-02-23, 7:03 pm

ben.jenson@gmail.com wrote:
> 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 :)
>


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);
}
}

--

Knute Johnson
email s/nospam/knute/
ben.jenson@gmail.com

2006-02-27, 7:09 pm

knute u r a star :) thanks

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com