我从互联网上下载了以下代码,之前它运行良好,但现在显示错误:
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(ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e)
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)
{
dispose(); //It releases all memory for this window and make the window undisplayable
}
});
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();
}
}
}
在执行mplayer.realize
时显示以下错误行 Error: Unable to realize com.sun.media.codec.video.jmpx.Jmpx@1751a9e
让我告诉我在jmpx包中没有Jmpx @ 1751a9e。我不知道如何得到一个。请帮忙
答案 0 :(得分:2)