Flash AS3 and webcam: problems with AIR - actionscript-3

I'm having some problems getting the Flash AS3 Camera to work correctly. If you could help, much appreciated. I looked at olThe details:
I'm able, when publishing to a SWF, to get the webcam up and running and all works fine, popping up the 'may I access your camera dialog' which returns muted or not.
• First question: is there any way to make it so I can bypass the user permission, that is always grant it? We are running a kiosk app. Will the following method work for an AIR app? https://stackoverflow.com/questions/3266939/flash-grant-access-to-webcam-programmatically-behind-the-scenes
• Second question: as I said, I can get the webcam/Camera hookup to work fine when publishing for SWF in IDE, and in browser. But if I switch the project to publish for AIR and run the air app, or test in the IDE, I don't get the security permissions dialog coming up at all. Nothing. Perhaps the security box is off screen? Is there some way to control the placement? Is there something different about using the webcam from within AIR?
I'm happy to NOT publish to AIR, but to use SWF — simply need to be able to read/write to XML files on local disk and think that AIR only way to do that?
Thanks for any help!
The code:
private function initTracking() : void
{
var camW : int = 840;
var camH : int = 640;
// Create the camera
_cam = Camera.getCamera();
if (_cam == null)
{
trace("Unable to locate available cameras.");
return;
}
else
{
trace("Found camera: " + _cam.name);
_cam.addEventListener(StatusEvent.STATUS, camStatusHandler);
_cam.setMode(camW, camH, stage.frameRate);
// Create a video
_vid = new Video(camW, camH);
_vid.attachCamera(_cam);
trace("camera ", _cam, " attached to video ", _vid);
// Create the Motion Tracker
_motionTracker = new MotionTracker(_vid);
// We flip the input as we want a mirror image
_motionTracker.flipInput = true;
}
}
private function camStatusHandler(event:StatusEvent):void
{
trace("camStatusHandler::");
if (_cam.muted)
{
trace("Unable to connect to active camera.");
}
else
{
trace("able to connect to active camera.");
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler, false,0,true);
}
// Remove the status event listener.
_cam.removeEventListener(StatusEvent.STATUS, camStatusHandler);
}

If you publish as AIR, there is no security dialog (the security box for swfs is there to stop 'hackers' gaining control of a users webcam without their knowledge).
If your code works in a swf, it should also work in an AIR app without needing any changes - assuming AIR is running on the desktop and not a mobile device?
If you are not seeing the webcam output when you publish as an AIR app, post the relevant code.
Edit:
The StatusEvent.STATUS event does not occur with AIR apps - it fires when user closes security dialog - hence camStatusHandler never gets called.
So remove camStatusHandler function completely and also this line:
_cam.addEventListener(StatusEvent.STATUS, camStatusHandler);
And add important code from camStatusHandler to the end of initTracking:
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler, false,0,true);

Related

Distriqt GameServices ANE - Apple Game Center Problem

I'me developing a game in AS3 AIR and I'me using Distriqt GameServices native extension.
The problem is that I can not sign in to Apple Game Center.
In the documentation, it's stated that: If Google Play Services aren’t available then you won’t be able to use the functionality in this extension.
And there's a code snippet:
var result:int = GoogleApiAvailability.instance.isGooglePlayServicesAvailable();
if (result != ConnectionResult.SUCCESS) {
if (GoogleApiAvailability.instance.isUserRecoverableError( result )) {
GoogleApiAvailability.instance.showErrorDialog( result );
} else {
trace( "Google Play Services aren't available on this device" );
}
} else {
trace( "Google Play Services are Available" );
//init here
}
That sounds odd to me because Google Play Services are not available on iOS, naturally.
I've tried to skip this step and initialize the service without checking GoogleApiAvailability. But I'm getting this message after a successful initialization and then calling signIn() method:
The requested operation could not be completed because local player has not been authenticated.
That sounds odd too, because this is the authentication method itself!!
I'm almost sure that my setup is correct. And the extension is working fine on Android.
GameServices ANE Version: 5.0.011
Any help is appreciated,
Thanks
Ah, actually that had nothing to do with the Distriqt GameServices, so sorry.
The message "The requested operation could not be completed because local player has not been authenticated." was coming from iOS meaning the Game Center is not activated on the device.
Switching on Game Center in the device (settings-> gamecenter) solved the issue.

In flash as3 webcam how to get newly connected webcam name at run-time?

I have a flash as3 based webcam video recorder that publishes the webcam video stream and to do this i am using the following codes :
var camera:Camera = Camera.getCamera(0);
var arr:Array = Camera.names;
if(camera != null)
{
videoWidth = topBorderContainer.width;
videoHeight = topBorderContainer.height;
camera.setMode(videoWidth, videoHeight, 30, false);
camera.setQuality(0, 100);
if (camera)
{
videoDisplay.videoObject.attachCamera(camera);
}
}
But problem is that if i am connecting a new document camera at run time and running my webcam tool then Camera.names returning the previously connected document camera name instead of returning the new document camera name.
And to get new document webcam name i have to restart my application again.
But i have no knowledge how to get newly connected document camera name at run time so if anybody know how to get the newly connected document camera name at run time please help me to solve.
It is very likely that you will not be able to pull the trick:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#getCamera()
"Scanning the hardware for cameras takes time. When the runtime finds at least one camera, the hardware is not scanned again for the lifetime of the player instance. However, if the runtime doesn't find any cameras, it will scan each time getCamera is called. This is helpful if the camera is present but is disabled; if your SWF file provides a Try Again button that calls getCamera, Flash Player can find the camera without the user having to restart the SWF file."
It is possible that Flash Player treats Workers (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Worker.html) as separate Flash Player instances and thus a new Worker would be able to access the renewed list of Cameras. You might want to try it.

Unauthorized Access Exception when Creating an instance of SpeechSynthesizer in WP8.1 Emulator

I was trying to recreate the simle Text to Speech example used on the MSDN website. However whenever the code came to create the instance of the SpeechSynthesizer class it failed with a Unauthorised Acception error when running on the WP8.1 emulator. I currently do not have an actual device to test on to see if this makes a difference.
My code was simply:
private async void TTS()
{
// The media object for controlling and playing audio.
MediaElement mediaElement = new MediaElement();
// The object for controlling the speech synthesis engine (voice).
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
// Generate the audio stream from plain text.
SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Hello World");
// Send the stream to the media object.
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
}
I know there was an issue with the SpeechSynthesizer in Windows 8.1, and I found solutions to this when looking to fix the problem, but found little about the problem with WP8.1 SpeechSynthesizer. Has anybody else came across this problem and found a fix?
You should add one DeviceCapability in Package.appxmanifest file:
In DeviceCapability Tab, check the microphone, because it will provides access to the microphone’s audio feed, which allows the app to record audio from connected microphones.
Look at this library: App capability declarations (Windows Runtime apps)

Adobe AIR, how to open a scene in a new window

I'm developing a networked AIR application in Flash Professional. I need to open two instances of the application and after searching I found that launching the app multiple times just causes an invoke event to be sent to the currently running app.
Up until now I've been using NetConnection & NetGroup (Supported by Flash Player 10.1+), now that I'm using ServerSocket & Socket, it requires the AIR 2+ runtime.
I found a solution to open a window on invoke.
my solution would be to launch a new window on invoke
function openWindow():void
{
newWin = new NativeWindow(init); //Initialize the Native Window
newWin.activate();
newWin.height = 200;
newWin.width = 300;
newWin.title = "My First New Win!";
}
and have it
gotoAndPlay(1, "Scene 1");
Is there a way to execute that on the new window? Or is there a way to open two instances of an AIR app?
Edit
You can open two instances of the same air app by changing it's ID. However, this is a very involved process every time I want to debug!
Turns out AIR on Android doesn't support ServerSockets. This means I must use non-AIR flash methods to achieve communication.
I can then achieve network testing through multiple Flash Player instances.
I don't believe ADL has the ability to run more than instance at a time.

actionscript 3 filereference 'save' throws error

i have a code which saves a display object locally as an image file, but at some point it began throwing error 2174. this code is called either from context-menu click event or keyboard event.
var sourceBmd:BitmapData = new BitmapData(displayObject.width,displayObject.height);
sourceBmd.draw(displayObject,new Matrix(displayObject.width,0,0,displayObject.height));
var jpgEncoder:JPGEncoder = new JPGEncoder(80);
var byteArray:ByteArray = jpgEncoder.encode(sourceBmd);
try
{
filereference.save(byteArray,"posterImage.jpg");
}
catch (e:Error)
{
Debugging.alert("error: ",e.message);
}
as you can see, the filereference has only a single action - so no reason for error 2174 to be thrown.
in case you wonder - i'm publishing for flash player 10.0
UPDATE: i found it it has to do with the flash player version: on 10.3 it works, while on 11.1 if fails.
any ideas?
cheers,
eRez
filereference.save needs to be called from a user action IE: mouse click
If it isn't you will get that error.
Also Publish for version 10 or higher.
Also per the docs.
Note that because of new functionality added to the Flash Player, when publishing to Flash Player 10, you can have only one of the following operations active at one time: FileReference.browse(), FileReference.upload(), FileReference.download(), FileReference.load(), FileReference.save(). Otherwise, Flash Player throws a runtime error (code 2174). Use FileReference.cancel() to stop an operation in progress. This restriction applies only to Flash Player 10. Previous versions of Flash Player are unaffected by this restriction on simultaneous multiple operations.
Does this link solve your problem?
Also, did you try restarting flash IDE after the error occurred?
by reading through the docs, i can assume:
you're running in flash player 10
you don't call filereference.cancel() in cases like when the user clicks "cancel" or "close" on the dialogue box that opens; try it