How to record video using the as3 camera class - actionscript-3

I'm trying to add video recording into a mobile app I'm building. But am struggling with the recording part. So far I have got the camera class displaying in a video object with the code below.
private function init():void
{
var camera1:Camera = Camera.getCamera();
trace(Camera.names);
if (camera1)
{
var ui1:UIComponent = new UIComponent();
var video:Video = new Video (320, 240);
camera1.setMode(320, 240, 24);
camera1.setQuality(0, 100);
video.attachCamera(camera1);
ui1.addChild(video);
cameraGroup1.addElement(ui1);
}
}
From what I understand you can use the cameraUI class instead to achieve the recording part and add it to the library but it would mean using the default camera application when I would rather use my own. I imagine recording using the camera class would require a tick to grab each frame and then something like the videoFrame event but could really use some code or a point in the right direction.
Thanks in advance.

Best way to record using the Flash or AIR application is Media Server. You can connect your application with Media Server (Flash Media Server / Red5 / any other Media Server which is providing Media Recording and Publishing.) and publish your stream for recording.
Second way, I need to search out the code but logically I can say answer. We need to convert Camera stream buffer in to the binary data and we need to save binary data as video file o File system.
For that you can write down some code in ActionScript and need to write down some code in the Native Application as Native Extension.

Related

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)

create (webcam capture like youtube) in my website

I have a website working the same as youtube. At this moment I am trying to create a video image captured by WEBCAM.
The video image should be saved on my computer (by FLV format) first and then if the user is satisfied, he or she can upload it on the server
I am trying to use Actionscript3 in Adobe flash CS5 and Flash media server4
1- How can I do that?
2- Is the flash media server needed?
Please pay attention that we would like to allow the user to save video on his/her computer and then be able to uploaded to the server.
Many thanks.
Assuming the computer can take the overhead of doing the encoding on the fly (or has enough memory to buffer the data then can run the data through an encoding process) then the library mentioned in the SO answer here should work:
Encode video from any format to .flv format in AS3
I believe the Flash media server would only really be necessary in this case for broadcast.
Pseudocode example
private var cam:Camera;
public function Whatever()
{
//In constructor
addEventListener(Event.ENTER_FRAME, grabFrame);
cam = Camera.getCamera();
if (cam != null)
{
var vid:Video = new Video(cam.width, cam.height);
vid.attachCamera(cam);
addChild(vid);
}
}
private function grabFrame(event:Event):void
{
var bd:BitmapData = new BitmapData(cam.width, cam.height)
bd.draw(vid);
//now the BitmapData has a frame of the video, at this point you also
//would want to capture the audio then use the FLV class in the library
}
You can also check out using Red5 as an alternative open source video stream recorder.
http://distriqt.com/post/493
Cheers

Adobe Air - Choose webcam manually

How to choose the webcam/camera manually in Adobe Air? In Flash it's working through this:
Security.showSettings(SecurityPanel.CAMERA);
Is there something like that in Adobe Air?
Thank
In the Adobe Air Player (up to 3.4) there is no equivalent of the Flash Player security panel that can be triggered with Security.showSettings(SecurityPanel.CAMERA);
If you want to let the user pick a camera, you will have to create some sort of menu by using the info from the Camera.names array. Then, you can assign the user's choice via code by using something like :
var cam:Camera = Camera.getCamera('1');
Important: contrary to what was said above you CANNOT specify the camera by name. The getCamera() function expects a string representation of the camera's index number as a parameter. This is weird behaviour but it's how it works. So if you want to retrieve the second camera, you will have to pass the string '1' to the getCamera() function.
If you try to set the camera by specifying it's name, the function will return null.
I don't think there is any feature that you can use to select camera in AIR.
Instead you have to do it by coding.
get list of cameras using Camera.names property and then get selected camera instance using Camera.getCamera("name of camera");
I think this is best way to Do it.
Do you really need that typical dialog?
You can set a camera manually first by showing a list by:
var cameraNames:Array = Camera.names;
And then.....
var cameraInstance:Camera = Camera.getCamera('selectedCameraName');

AS3-ID3 event in a web radio

I'm building an online radio player using the AS3 code below:
private var soundChannel:SoundChannel;
private var stationUrl:String = "h t t p : / /205.188.215.230:8002/";
sound = new Sound();
sound.addEventListener(Event.ID3, onID3Change);
sound.load(new URLRequest(stationUrl));
soundChannel = sound.play();
private function onID3Change(e:Event):void
{
....
}
the sound plays successfully, but the problem is that the ID3 event is never triggered!
Does anyone know how to solve this?
ID3 doesn't exist in internet radio streams like this one. I am assuming you're talking about a SHOUTcast/IceCast stream.
For that, you need to implement the icy metadata protocol. For Flash, this is generally just done externally.
See this reference: http://www.smackfu.com/stuff/programming/shoutcast.html
Basically, you send icy-metadata: 1 in the headers of your GET request. The server then inserts metadata right into the middle of the stream, which you pull out before sending the data on to whatever is playing the stream. I'm not sure if this is even possible in Flash, but it certainly is possible to do this in PHP (or any server-side language really) and have your Flash application make a request to your PHP script to get that metadata.