2012-07-06 2 views
1

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) 
+1

난 당신이 JFrame의/JPanel의 또 다른 클래스가 있다고 가정? 네가 수업을 놓친 것 같아. 어쩌면 당신은 그것을 가져올 필요가 있을지도 모르거나 당신이 보이지 않는 코드의 다른 부분에서 진행될 수 있습니다. 이 모든 코드입니까? –

+0

* "일부 요구 사항에 대해서는 애플릿으로 포장해야합니다"* 요구 사항은 무엇입니까? 네트워크를 통해 전달하려면 [Java Web Start] (http://stackoverflow.com/tags/java-web-start/info)를 사용하여 링크에서 시작하십시오. 사용자에게 더 좋고 배포 및 유지 관리의 어려움이 적습니다. –

+0

귀하의 답변에 감사드립니다 ... @ AndrewThompson 제 경우에는 사용자 (클라이언트)가 특별히 애플릿을 사용하여 웹에서 실행되는 응용 프로그램을 원합니다 ...이 코드는 현재 웹에서도 임베드 할 수 있습니다. – Ruby

답변

0

내가 ...이 코드를 실행 할 수 있었다 애플릿의 init 메소드에서 내가 클래스의 객체를 불러 이 스레드는 ...

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"); 
     } 
    } 
내가 아니라 내 웹 페이지에 애플릿을 삽입 한

....

관련 문제