Code: Select all
while((robotBitmapURL != null) && (Thread.currentThread() == ipCameraSnapshotGrabber)) {
try {
//robotBitmapURL has the form "http://UID:pwd@ipaddress:80/cgi-bin/snapshot.cgi?"
connection = (HttpURLConnection)robotBitmapURL.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", "Basic " + authStringEncoded);
connection.setDoInput(true);
connection.connect();
snapShotStream = connection.getInputStream();
synchronized (AmcrestIPCamera.this) {
snapShot[latestSnapshot] = BitmapFactory.decodeStream(snapShotStream);
latestSnapshot = 1 - latestSnapshot;//Flip the double buffer index, to point to the next buffer
}
snapShotStream.close();
connection.disconnect();
//Insert the proper bitmap into the "robot's eye view" display, i.e., the bitmap pointed to
// BEFORE the double buffer index was flipped! (Scheduled on the UI Thread)
deliverThenDrawBitmap(snapShot[1 - latestSnapshot]);
} catch (Exception e) {
//------------------------------
}
}
Why is this happening? And how can I work around it?
