не удается захватить прямую трансляцию в апплете

Я запускаю следующий код для захвата потокового видео в реальном времени с ip-камеры. Он хорошо работает, если я использовал Jframe, для некоторых требований мне нужно обернуть его в апплет, но он не работает, может кто-нибудь помочь.

private static final long serialVersionUID = 1L;
public boolean useMJPGStream = false;//true;
public String jpgURL="http://192.168.x.x:80/video.cgi/jpg/image.cgi?resolution=640×480";
public String mjpgURL="http://192.168.x.x:80/video.cgi/mjpg/video.cgi?resolution=640×480";
DataInputStream dis;
private Image image = null;
public Dimension imageSize = null;
public boolean connected = false;
private boolean initCompleted = false;
HttpURLConnection huc = null;
Component parent;
/** Creates a new instance of Ax52Camera */
public void init()
{
new Thread(this).start();
}
public void connect(){
try{
URL u = new URL(useMJPGStream?mjpgURL:jpgURL);
huc = (HttpURLConnection)u.openConnection();
System.out.println(huc.getContentType());
InputStream is = huc.getInputStream();
System.out.println(is.toString());
connected = true;
BufferedInputStream bis = new BufferedInputStream(is);
dis= new DataInputStream(bis);
if (!initCompleted) initDisplay();
}catch(IOException e){ //incase no connection exists wait and try again, instead of printing the error
try{
huc.disconnect();
Thread.sleep(33);
}catch(InterruptedException ie){huc.disconnect();connect();}
connect();
}catch(Exception e){;}
}
public void initDisplay(){ //setup the display
if (useMJPGStream)readMJPGStream();
else {readJPG();disconnect();}
imageSize = new Dimension(image.getWidth(this), image.getHeight(this));
setPreferredSize(imageSize);
this.setSize(imageSize);
this.validate();
initCompleted = true;
}
public void disconnect(){
try{
if(connected){
dis.close();
connected = false;
}
}catch(Exception e){;}
}
public void paint(Graphics g) { //used to set the image on the panel
if (image != null)
g.drawImage(image, 0, 0, this);
}
public void readStream(){ //the basic method to continuously read the stream
try{
if (useMJPGStream){
while(true){
readMJPGStream();
this.repaint();
}
}
else{
while(true){
connect();
readJPG();
this.repaint();
disconnect();
}
}
}catch(Exception e){;}
}
public void readMJPGStream(){ //preprocess the mjpg stream to remove the mjpg encapsulation
readLine(3,dis); //discard the first 3 lines
readJPG();
readLine(2,dis); //discard the last two lines
}
public void readJPG(){ //read the embedded jpeg image
try{
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(dis);
image = decoder.decodeAsBufferedImage();
}catch(Exception e){e.printStackTrace();disconnect();}
}
public void readLine(int n, DataInputStream dis){ //used to strip out the header lines
for (int i=0; i<n;i++){
readLine(dis);
}
}
public void readLine(DataInputStream dis){
try{
boolean end = false;
String lineEnd = "\n"; //assumes that the end of the line is marked with this
byte[] lineEndBytes = lineEnd.getBytes();
byte[] byteBuf = new byte[lineEndBytes.length];
while(!end){
dis.read(byteBuf,0,lineEndBytes.length);
String t = new String(byteBuf);
//System.out.print(t); //uncomment if you want to see what the lines actually look like
if(t.equals(lineEnd)) end=true;
}
}catch(Exception e){e.printStackTrace();}
}
public void run() {
connect();
readStream();
}

}

я получаю следующую ошибку

load: class com.javaprac.AxisCamera1.class not found.
java.lang.ClassNotFoundException: com.javaprac.AxisCamera1.class
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadCode(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

person Ruby    schedule 06.07.2012    source источник
comment
Я предполагаю, что у вас есть другой класс для JFrame/JPanel? Похоже, вы просто пропустили урок. Возможно, вам нужно импортировать его, или, может быть, что-то происходит в другой части кода, которую вы не показываете. Это весь код?   -  person Dominick Piganell    schedule 06.07.2012
comment
для некоторых требований мне нужно обернуть их в апплет Какое требование? Если нужно доставить его по сети, используйте Java Web Start, чтобы запустить его по ссылке. Удобнее для пользователя и меньше проблем с развертыванием и обслуживанием.   -  person Andrew Thompson    schedule 06.07.2012
comment
спасибо за ваши ответы ... @AndrewThompson в моем случае пользователь (клиент) специально хочет, чтобы приложение запускалось в Интернете с помощью апплета ... теперь этот код работает, я также могу встроить его в сеть ...   -  person Ruby    schedule 10.07.2012


Ответы (1)


Я смог запустить этот код... в методе инициализации апплета я назвал объект класса и поток, подобный этому...

public void init() {
        ViewCamera axPanel = new ViewCamera(rootPane);
        axPanel.setOpaque(true);
        new Thread(axPanel).start();
        getContentPane().add(axPanel);

        // Execute a job on the event-dispatching thread; creating this applet's
        // GUI.
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {

                    createGUI();

                }
            });
        } catch (Exception e) {
            System.err.println("createGUI didn't complete successfully");
        }
    }

я также встроил этот апплет на свою веб-страницу ....

person Ruby    schedule 10.07.2012