Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seeking Problem

Status
Not open for further replies.

AdiMM

Programmer
Mar 14, 2006
1
RO
Hello.
I tryed to run the Seek.java program that is on sun java website.But it's not working, so i get the "The player does not support FramePositioningControl" error message. It seems all the programs that are using frame seeking or frame grabbing methods are not working on video files.I don't understand why. Does anybody have this problem, or knows what I could do?

10x

import java.awt.*;
import java.awt.event.*;
import javax.media.*;
import javax.media.control.FrameGrabbingControl;
import javax.media.control.FramePositioningControl;
import javax.media.protocol.*;


/**
* Sample program to demonstrate FramePositioningControl.
*/
public class Seek extends Frame implements ControllerListener, ActionListener {

Player p;
FramePositioningControl fpc;
Object waitSync = new Object();
boolean stateTransitionOK = true;
int totalFrames = FramePositioningControl.FRAME_UNKNOWN;

Panel cntlPanel;
Button fwdButton;
Button bwdButton;
Button rndButton;

/**
* Given a DataSource, create a player and use that player
* as a player to playback the media.
*/
public boolean open(DataSource ds) {

System.err.println("create player for: " + ds.getContentType());

try {
p = Manager.createPlayer(ds);
} catch (Exception e) {
System.err.println("Failed to create a player from the given DataSource: " + e);
return false;
}

p.addControllerListener(this);

p.realize();
if (!waitForState(p.Realized)) {
System.err.println("Failed to realize the player.");
return false;
}

// Try to retrieve a FramePositioningControl from the player.

fpc = (FramePositioningControl)p.getControl("javax.media.control.FramePositioningControl");
if (fpc == null) {
System.err.println("The player does not support FramePositioningControl.");
System.err.println("There's no reason to go on for the purpose of this demo.");
return false;
}

Time duration = p.getDuration();

if (duration != Duration.DURATION_UNKNOWN) {
System.err.println("Movie duration: " + duration.getSeconds());

totalFrames = fpc.mapTimeToFrame(duration);
if (totalFrames != FramePositioningControl.FRAME_UNKNOWN)
System.err.println("Total # of video frames in the movies: " + totalFrames);
else
System.err.println("The FramePositiongControl does not support mapTimeToFrame.");

} else {
System.err.println("Movie duration: unknown");
}

// Prefetch the player.
p.prefetch();
if (!waitForState(p.Prefetched)) {
System.err.println("Failed to prefetch the player.");
return false;
}

// Display the visual & control component if there's one.

setLayout(new BorderLayout());

cntlPanel = new Panel();

fwdButton = new Button("Forward");
bwdButton = new Button("Backward");
rndButton = new Button("Random");

fwdButton.addActionListener(this);
bwdButton.addActionListener(this);
rndButton.addActionListener(this);

cntlPanel.add(fwdButton);
cntlPanel.add(bwdButton);
cntlPanel.add(rndButton);

Component vc;
if ((vc = p.getVisualComponent()) != null) {
add("Center", vc);
}

add("South", cntlPanel);

setVisible(true);

return true;
}


public void addNotify() {
super.addNotify();
pack();
}


/**
* Block until the player has transitioned to the given state.
* Return false if the transition failed.
*/
boolean waitForState(int state) {
synchronized (waitSync) {
try {
while (p.getState() < state && stateTransitionOK)
waitSync.wait();
} catch (Exception e) {}
}
return stateTransitionOK;
}


public void actionPerformed(ActionEvent ae) {
String command = ae.getActionCommand();
if (command.equals("Forward")) {
int dest = fpc.skip(1);
System.err.println("Step forward " + dest + " frame.");
} else if (command.equals("Backward")) {
int dest = fpc.skip(-1);
System.err.println("Step backward " + dest + " frame.");
} else if (command.equals("Random")) {
if (totalFrames == FramePositioningControl.FRAME_UNKNOWN)
System.err.println("Cannot jump to a random frame.");
else {
int randomFrame = (int)(totalFrames * Math.random());
randomFrame = fpc.seek(randomFrame);
System.err.println("Jump to a random frame: " + randomFrame);
}
}

int currentFrame = fpc.mapTimeToFrame(p.getMediaTime());
if (currentFrame != FramePositioningControl.FRAME_UNKNOWN)
System.err.println("Current frame: " + currentFrame);
}


/**
* Controller Listener.
*/
public void controllerUpdate(ControllerEvent evt) {

if (evt instanceof ConfigureCompleteEvent ||
evt instanceof RealizeCompleteEvent ||
evt instanceof PrefetchCompleteEvent) {
synchronized (waitSync) {
stateTransitionOK = true;
waitSync.notifyAll();
}
} else if (evt instanceof ResourceUnavailableEvent) {
synchronized (waitSync) {
stateTransitionOK = false;
waitSync.notifyAll();
}
} else if (evt instanceof EndOfMediaEvent) {
p.setMediaTime(new Time(0));
//p.start();
//p.close();
//System.exit(0);
} else if (evt instanceof SizeChangeEvent) {
}
}



/**
* Main program
*/
public static void main(String [] args) {

if (args.length == 0) {
prUsage();
System.exit(0);
}

MediaLocator ml;

if ((ml = new MediaLocator(args[0])) == null) {
System.err.println("Cannot build media locator from: " + args[0]);
prUsage();
System.exit(0);
}

DataSource ds = null;

// Create a DataSource given the media locator.
try {
ds = Manager.createDataSource(ml);
} catch (Exception e) {
System.err.println("Cannot create DataSource from: " + ml);
System.exit(0);
}

Seek seek = new Seek();
if (!seek.open(ds))
System.exit(0);
}

static void prUsage() {
System.err.println("Usage: java Seek <url>");
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top