Gentili utenti,
vi scrivo per chiedervi aiuto iguardo il problema in oggetto.
Possego una IP CAM Vivotek IP3133 collegata ad un modem router TP-LINK TD-W8920G
Ho installato la JMF 2.1.1e
javac -version: 1.6.0_03
java -version: 1.6.0_07
Ho creato un programma ma mi da due warning, esattamente uguali, quando lo compilo:
warning: com.sun.image.codec.jpeg.JPEGImageDecoder is Sun proprietary API and may be removed in a future release
In basso vi posto il codice che attualmente utilizzo però credo ci siano dei problemi con gli indirizzi IP (ma non credo siano solo questi):
String jpgURL = "http://192.168.1.100/cgi-bin/video.jpg"; e questo penso sia giusto in quanto mi da uno snapshot.
Sono invece insicuro sul seguente: public String mjpgURL= "http://192.168.1.100/video.cgi";
L'indirizzo http://192.168.1.100 è l'indizzo privato della cam collegata in rete
Spero qualcuno possa aiutarmi
Codice PHP:import java.net.*;
import com.sun.image.codec.jpeg.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import java.applet.*;
public class IPCamera extends Applet implements Runnable
{
public boolean useMJPGStream = true;
String appletToLoad;
Thread appletThread;
public String jpgURL = "http://192.168.1.100/cgi-bin/video.jpg";
public String mjpgURL = "http://192.168.1.100/video.cgi";
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 AxisCamera */
public IPCamera (Component parent_) //
{ //
parent = parent_; //
} //
public void connect(){
try{
URL u = new URL(useMJPGStream?mjpgURL:jpgURL);
huc = (HttpURLConnection) u.openConnection();
//System.out.println(huc.getContentType());
InputStream is = huc.getInputStream();
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(60);
}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); //
parent.setSize(imageSize); //
parent.validate(); //
initCompleted = true;
}
public void disconnect(){
try{
if(connected){
dis.close();
connected = false;
}
}catch(Exception e){;}
}
public void init(){
System.out.println("Starting Applet");
appletToLoad = getParameter("appletToLoad");
setBackground(Color.white);
}
public void paint(Graphics g){
//used to set the image on the panel
if (image != null)
g.drawImage(image, 0, 0, this);
}
/*public void run()
{
try {
connect();
readStream();
Class appletClass = Class.forName(appletToLoad);
Applet realApplet = (Applet)appletClass.newInstance();
//realApplet.setStub(this);
setLayout( new GridLayout(1,0));
add(realApplet);
realApplet.init();
realApplet.start();
}
catch (Exception e) {
System.out.println( e );
}
validate();
}*/
public void start(){
appletThread = new Thread(this);
appletThread.start();
}
public void stop(){
appletThread.stop();
appletThread = null;
}
public void readStream(){
//the basic method to continuously read the stream
try{
if (useMJPGStream){
while(true){
readMJPGStream();
//parent.repaint();
}
}
else{
while(true){
connect();
readJPG();
//parent.repaint();
disconnect();
}
}
}catch(Exception e){;}
}
public void readMJPGStream(){
//preprocess the mjpg stream to remove the mjpg encapsulation
//Following commented on 07/08/2006
//readLine(3,dis); //discard the first 3 lines
//Following added on 07/08/2006
readLine(4, dis); //discard the first 4 lines for D-Link DCS-900
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();
System.out.println("lineEndBytes....."+lineEndBytes);
byte[] byteBuf = new byte[lineEndBytes.length];
System.out.println("byteBuf......."+byteBuf);
while(!end){
//dis.read(byteBuf,0,lineEndBytes.length);
String t = "";
if(byteBuf != null){
dis.read(byteBuf,0,lineEndBytes.length);
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();
}
public static void main(String[] args)
{
JFrame jframe = new JFrame();
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//IPCamera axPanel = new IPCamera();
IPCamera axPanel = new IPCamera(jframe);
new Thread(axPanel).start();
jframe.getContentPane().add(axPanel);
jframe.pack();
jframe.show();
}
}

Rispondi quotando