aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes JMF FormatControl Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JMF FormatControl Problem" Watch "JMF FormatControl Problem" New topic
Author

JMF FormatControl Problem

David Ball
Greenhorn

Joined: Jul 07, 2004
Posts: 2
Ok, I've been racking my brain on this for a while now. I'm pretty much a JMF beginner so there may be something very basic I'm missing. Anyway, here is the problem. I have an application that takes in video streams and displays them in a sort of video chatroom, and everything is going fine except that I can't seem to work through the custom control interfaces. More specifically I want to be able to resize the video component at the press of a button and control the frame rate (with a slider or something). I'm attempting to use the FormatControl and FrameRateCOntrol objects but am not having any luck actually changing anything. Here is the code for one of my classes, there are basically three buttons that, when clicked, should change the resolution ot the video:

-------------------------------------------------------------------------

public class VidWindow extends JFrame implements ActionListener, WindowListener{
private DataSource ds;
private Player play;
private JPanel buttonPanel;
private JButton closeButton, smallButton, mediumButton, largeButton;
private ImageIcon smallIcon, mediumIcon, largeIcon;
private FormatControl fc;
private Format form;
private Format[] formats;
private Dimension size;


public VidWindow(DataSource ds){
this.ds = ds;
init();
setSizeMid();
pack();
setVisible(true);
}

private void init(){
getContentPane().setLayout(new BorderLayout());

try {
play = Manager.createRealizedPlayer(ds);
} catch (NoPlayerException e) {
e.printStackTrace();
} catch (CannotRealizeException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

while(play.getState() != Player.Realized){

}

play.start();
Component vid = play.getVisualComponent();
getContentPane().add(BorderLayout.CENTER, vid);

buttonPanel = new JPanel();

smallIcon = new ImageIcon("small.gif");
mediumIcon = new ImageIcon("medium.gif");
largeIcon = new ImageIcon("large.gif");

smallButton = new JButton();
mediumButton = new JButton();
largeButton = new JButton();
closeButton = new JButton("Close Window");

smallButton.addActionListener(this);
mediumButton.addActionListener(this);
largeButton.addActionListener(this);
closeButton.addActionListener(this);

smallButton.setIcon(smallIcon);
mediumButton.setIcon(mediumIcon);
largeButton.setIcon(largeIcon);

smallButton.setBorder(null);
mediumButton.setBorder(null);
largeButton.setBorder(null);

buttonPanel.add(smallButton);
buttonPanel.add(mediumButton);
buttonPanel.add(largeButton);
buttonPanel.add(closeButton);

getContentPane().add(BorderLayout.SOUTH, buttonPanel);


}

private void doClose(){
play.stop();
play.close();
setVisible(false);
}

private void setVid(){
fc = (FormatControl) play.getControl("javax.media.control.FormatControl");
formats = fc.getSupportedFormats();
for(int i =0; i<formats.length;i++){
form = formats[i];
if(form.getClass().getName().equals("javax.media.format.RGBFormat")){
RGBFormat rgb = new RGBFormat();
if(((VideoFormat) form).getSize() == size){
fc.setFormat(form);
}

}
}
}

private void setSizeSmall(){
size = new Dimension(176,144);
setVid();
pack();
validate();
}

private void setSizeMid(){
size = new Dimension(320, 240);
setVid();
validate();
}

private void setSizeLarge(){
size = new Dimension(325, 288);
setVid();
validate();
}

public void actionPerformed(ActionEvent evt) {
Object obj = evt.getSource();
if(obj == closeButton){
doClose();
}
else{
fc = (FormatControl) play.getControl("javax.media.control.FormatControl");
formats = fc.getSupportedFormats();
for(int i =0; i<formats.length;i++){
form = formats[i];
if(form.getClass().getName().equals("javax.media.format.RGBFormat")){
RGBFormat rgb = new RGBFormat();
if(obj == smallButton){
setSizeSmall();
}
else if(obj == mediumButton){
setSizeMid();
}
else{
setSizeLarge();
}
}
}
}

}

---------------------------------------------------------------------------------------

Thanks for the help!

-Dave
Seweryn Jagusiak
Greenhorn

Joined: Jan 30, 2010
Posts: 1
In all Controls (which you can get by player.getControls() ), are 2 instances of FormatControl. Try to use another, searching list of controls with using operator instanceof (instanceof FormatControl)
Additionally,you should use:
if(((VideoFormat) form).getSize().equals( size))
insted of
if(((VideoFormat) form).getSize() == size)
Last thing:
you have to stop player during setting format
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMF FormatControl Problem