Skip to main content

JMF Error

No replies
mdyusufali786
Offline
Joined: 2012-10-17
Points: 0

I have download a JMF program from net to play video. The program was running well playing the video file stated in the code. But after a week when i run the program it did not play the file. An error was shown given below. The entire code with error is given below:

import com.sun.media.codec.video.jmpx.*;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.URL;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.EndOfMediaEvent;
import javax.media.Manager;
import javax.media.Player;
import javax.media.PrefetchCompleteEvent;
import javax.media.RealizeCompleteEvent;
import javax.media.Time;
import javax.swing.*;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;

public final class JavaVideo extends Frame//UtilityMethods
{
    Player player=null;
    Player newPlayer=null;
    JDesktopPane desktopPane=null;
    JMFrame jmFrame=null;
    String filename;
    URL url=null;
    public int windowWidth=0;
    public int windowHeight=0;
    Dimension screenSize=null;
    JPanel btnPanel=null;
    static JButton btnVideo1=null;
    static JButton btnVideo2=null;
    static JButton btnClose=null;
    //UtilityMethods um=new UtilityMethods();

   public JavaVideo()
    {}     

    public JavaVideo(String file_name)
    {
        //Determine the current screen resolution
        screenSize=Toolkit.getDefaultToolkit().getScreenSize();
        //Toolkit toolkit =

        //Add Desktop Pane
        setTitle("IP Camera");
        setLayout(new BorderLayout());
        desktopPane=new JDesktopPane();
        desktopPane.setDoubleBuffered(true);

        add("Center", desktopPane);

        //Add button pane and buttons to the main window
        btnPanel=new JPanel();
        btnPanel.setLayout(new GridLayout(20, 20));

        btnVideo1=new JButton("Video 1");
        btnVideo2=new JButton("Video 2");
        btnClose=new JButton("Close");
        btnClose.setMnemonic(KeyEvent.VK_C);

        btnPanel.add(btnVideo1);
        btnPanel.add(btnVideo2);
        btnPanel.add(btnClose);

        add("East", btnPanel);
        //End of adding buttons

        //Following line not working
        setSize(screenSize.width-50,screenSize.height-50);

        setLocationRelativeTo(null);

        setVisible(true);

        try
        {
            UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
        }
        catch(Exception e)
        {
            System.out.println("Error in setLookAndFeel :: "+e);
        }

        addWindowListener( new WindowAdapter()
        {
            @Override
            public void windowClosing(WindowEvent we)
            {
                System.exit(0);
            }
        } );

        btnClose.addActionListener(new ActionListener()
        {

            @Override
            public void actionPerformed(ActionEvent e)
            {
               //It releases all memory for this window
              //and make the window undisplayable  
               dispose();
            }
        });


        Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);

        this.filename="file:"+file_name;
        playVideoFile(filename);
    }

    public void playVideoFile(String fname)
    {
        String mediaFile=fname;

        try
        {
            //Create an url from the filename
            if((url=new URL(mediaFile))==null)
            {
                //Fatal("Can't build url for "+mediaFile);
                System.out.println("Can't build url for "+mediaFile);
                return;
            }

            //Create an instance of a player for this media
            try
            {
                player=Manager.createPlayer(url);
            }
            catch(Exception e)
            {
                System.out.println("Error in Creating Player :: "+e);
            }
        }
        catch(IOException ioE)
        {
            System.out.println("IO Error while Creating URL :: "+ioE);
        }
        catch(Exception e)
        {
            System.out.println("Error while Creating URL :: "+e);
        }

        if(player!=null)
        {
            //this.filename=filename;
            jmFrame=new JMFrame(player,filename);
            desktopPane.add(jmFrame);
        }
    }

    public Dimension SystemCurrentResolution()
    {
        Toolkit toolkit=Toolkit.getDefaultToolkit();
        Dimension dim=toolkit.getScreenSize();
        return dim;
    }

    public static void main(String[] args)
    {
        String file="/home/aruna/Desktop/JavaFiles/video/delta.mpg";
        JavaVideo javaVideo = new JavaVideo(file);
    }
}

class JMFrame extends JInternalFrame implements ControllerListener
{
    Player mplayer;
    Component visual = null;
    Component control = null;

    int videoWidth = 0;
    int videoHeight = 0;
    int controlHeight = 30;
    int insetWidth = 10;
    int insetHeight = 30;
    boolean firstTime = true;

    public JMFrame(Player player, String title)
    {
        super(title, true, true, true, true);
        getContentPane().setLayout( new BorderLayout() );
        setSize(320, 10);
        setLocation(50, 50);
        setVisible(true);
        mplayer = player;
        mplayer.addControllerListener((ControllerListener) this);
        mplayer.realize();

        addInternalFrameListener( new InternalFrameAdapter()
        {
            @Override
            public void internalFrameClosing(InternalFrameEvent ife)
            {
                mplayer.close();
            }
        } );
    }

    @Override
    public void controllerUpdate(ControllerEvent ce)
    {
        if (ce instanceof RealizeCompleteEvent)
        {
            mplayer.prefetch();
        }
        else if (ce instanceof PrefetchCompleteEvent)
        {
            if (visual != null)
                return;

            if ((visual = mplayer.getVisualComponent()) != null)
            {
                Dimension size = visual.getPreferredSize();
                videoWidth = size.width;
                //videoWidth = 800;
                videoHeight = size.height;
                //videoHeight = 600;
                getContentPane().add("Center", visual);
            }
            else
                videoWidth = 320;

            if ((control = mplayer.getControlPanelComponent()) != null)
            {
                controlHeight = control.getPreferredSize().height;
                getContentPane().add("South", control);
            }

            JavaVideo jv=new JavaVideo();

            setSize(videoWidth + insetWidth,videoHeight + controlHeight + insetHeight);
            //setSize(jv.windowWidth-100,jv.windowHeight-100);
            validate();
            mplayer.start();
        }
        else if (ce instanceof EndOfMediaEvent)
        {
            mplayer.setMediaTime(new Time(0));
            mplayer.start();

        }
    }
}

It shows the following error line on executing mplayer.realize

Error: Unable to realize com.sun.media.codec.video.jmpx.Jmpx@1751a9e

Please help to solve the problem