Well, I'm not sure there's anything I can do to work around this.

I'm recreating the video and the bitmap when I change camera dimensions.
But it seems that once a video is snapshotted into a bitmap,
the camera somehow remembers the resolution, and future snapshots of
a new video object attached to that camera always end up at the same size.
It doesn't make any sense and I can't even work around it because
the first snapshot could have happened outside of this code.
I did:
- show some text behind the video, so that selecting a non-working camera
gives a little feedback.
- cleaned up NPE that happened if clearSnapshot() was called when it was
already cleared.
- Detach the camera from the old video before setting up a new one


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@467 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Ray Greenwell
2008-04-17 00:47:38 +00:00
parent bc469abcdf
commit 05cd1b4048
@@ -7,9 +7,15 @@ import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.StatusEvent;
import flash.media.Camera;
import flash.media.Video;
import flash.text.TextField;
import com.threerings.util.MethodQueue;
// TODO: use PreferredCamera?
public class CameraSnapshotter extends Sprite
{
@@ -27,6 +33,11 @@ public class CameraSnapshotter extends Sprite
*/
public function CameraSnapshotter (cameraName :String = null)
{
// create a label behind the videos that only shows up if a camera doesn't work
var tf :TextField = new TextField();
tf.text = "Camera unavailable.";
addChild(tf);
setCameraName(cameraName);
}
@@ -96,6 +107,7 @@ public class CameraSnapshotter extends Sprite
clearSnapshot();
removeChild(_video);
_camera.setMode(width, height, fps, favorArea);
attachVideo();
}
@@ -118,8 +130,10 @@ public class CameraSnapshotter extends Sprite
if (_camera == null) {
return;
}
if (_video.parent == null) {
if (_bitmap.parent != null) {
removeChild(_bitmap);
}
if (_video.parent == null) {
addChild(_video);
}
}
@@ -134,6 +148,11 @@ public class CameraSnapshotter extends Sprite
protected function attachVideo () :void
{
if (_video != null) {
// shut down the old video
_video.attachCamera(null);
}
_video = new Video(_camera.width, _camera.height);
// the constructor args don't seem to do dick, so we set the values again...
_video.width = _camera.width;