record video using flash media server 4.5 - actionscript-3

Hello i am trying to capture my camera as an flv file with fms 4.5 i am doing the following:
protected function rec_clickHandler(event:MouseEvent):void
{
nc = new NetConnection();
nc.client = { onBWDone: function():void{ trace("onBWDone") } };
nc.connect("rtmp://localhost/vod");
nc.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
}
private function netStatusHandler(e:NetStatusEvent):void {
var code:String = e.info.code;
if(code == "NetConnection.Connect.Success"){ //in case of recording...
ns = new NetStream(nc);
ns.attachCamera(cam);
ns.attachAudio(mic);
ns.publish("filename","record");
}
else{
trace(code);
}
}
but i get the following error:
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetStream.Record.NoAccess
Can anyone help? what am i doing wrong?

This status message, NetStream.Record.NoAccess, generally indicates that you don't have write permissions to the stream. Check the permissions of your streams dir to see if it is read only.
If that is not the issue, check which application are you trying to publish to, does not SSAS that has code to deny write access to stream

Make sure the previously recorded video is not being opened in any video player. If it is being accessed by some other program, it will not allow you to record or rewrite it.

Related

Actionscript 3: Error #1009

I want to test and write if the microphone access was allowed or not in ActionScript 3 but now, ever if there is no compilation error, it doesn't ask me the microphone access, nothings happens when I launch the SWF file.
This is my code :
import flash.display.MovieClip;
import flash.events.StatusEvent;
import flash.media.Microphone;
var mic:Microphone = Microphone.getMicrophone();
if(mic){
mic.addEventListener(StatusEvent.STATUS, this.onMicStatus);
}
else{
trace("No micro");
}
function onMicStatus(event: StatusEvent): void {
if (event.code == "Microphone.Unmuted") {
trace("Microphone access was allowed.");
} else if (event.code == "Microphone.Muted") {
trace("Microphone access was denied.");
}
}
Your error comes from this line :
mic.addEventListener(StatusEvent.STATUS, this.onMicStatus);
because Microphone.getMicrophone() can return null :
If Microphone.getMicrophone() returns null, either the microphone is in use by another application, or there are no microphones installed on the system. To determine whether any microphones are installed, use Microphone.names.length (Microphone without "s", there is an error on Adobe's doc).
So to avoid that error, you can use a simple if statement :
if(mic){
mic.addEventListener(StatusEvent.STATUS, this.onMicStatus);
}
You can also use Microphone.names.length to verify if you have an Microphone installed (at least one) before creating a Microphone object :
if(Microphone.names.length > 0){
var mic:Microphone = Microphone.getMicrophone();
mic.addEventListener(StatusEvent.STATUS, this.onMicStatus);
}
Edit :
To display the Flash Player Microphone Settings panel, which lets the user choose the microphone to be referenced by Microphone.getMicrophone, use Security.showSettings().
To display the Flash Player Microphone Settings panel, you can use :
Security.showSettings(SecurityPanel.MICROPHONE);
Hope that can help.

Why am I receiving a flash player security error when trying to access facebook graph api photos?

I'm using the flash debug player(version 16) and I'm trying to access a users photo from within flash as3. Firstly, the Security error i'm receiving, here it is.
SecurityError: Error #2122: Security sandbox violation: Loader.content: http s://graffiti-galore.herokuapp.com/fb/GraffitiGalore.swf?build=0001 cannot access http s://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/v/t1.0-1/c46.46.570.570/s50x50/398269_10152199084495525_2139734276_n.jpg?oh=29be37fd74f7d338a7b5c23b9aadd474&oe=5548F552&gda=1431395518_d142c304e8b8afa8df340e6cac093b29. A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
at flash.display::Loader/get content()
at PictureBox/onCompleteLoadingImage()
I'm using the free Heroku dino that is being offered and I'm simply doing a fetch call to the graph api users object. fetching the id,first_name, last_name,picture.
The picture url comes back as hosted on https facebook servers.
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/v/t1.0-1/c46.46.570.570/s50x50/398269_10152199084495525_2139734276_n.jpg?oh=29be37fd74f7d338a7b5c23b9aadd474&oe=5548F552&gda=1431395518_d142c304e8b8afa8df340e6cac093b29
Links like the one above. For some reason i'm receiving this Security error whenever loading up the image from my flash as3 facebook app.
Below is the code i'm using to fetch the image.
[code]
public function setupPhoto(url:String):void
{
removeAllChildren();
var urlRequest1:URLRequest = new URLRequest(url);
this.loader1 = new Loader();
this.loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteLoadingImage);
this.loader1.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onErrorLoadingImage);
this.loader1.load(urlRequest1);
//imageLoader = new ImageLoader(url);
//imageLoader.addEventListener(Event.COMPLETE, onCompleteLoadingImage);
//imageLoader.load();
}
private function onErrorLoadingImage(e:IOErrorEvent):void
{
debugPanel.writeLine("ERROR LOADING IMAGE!!!");
debugPanel.writeLine(e.text);
}
public function onCompleteLoadingImage(e:Event):void
{
//var sprite:Sprite = this.loader1.content as Sprite;
//updatePicture(sprite);
updatePicture1(this.loader1.content);
}
[/code]
this works for me with Facebook:
var lc:LoaderContext = new LoaderContext(true, null, null);
// now add the LoaderContext to your loader
this.loader1.load(urlRequest1, lc);
you don't have to create a LoaderContext every time, just create it once and use everywhere.

Getting Bitmap from Video decoded with Nestream AppendBytes (AS3)?

I am wondering if someone who has handled NetStream.appendBytes in Flash knows how to get the bitmapData from a decoded video frame? I have already looked at this question but that is from 3 years ago and the more recent comment/answer seems to be gone. In 2014 has anyone managed to turn those bytes into a bitmap? I am working with Flash Player 11.8 and this is not a desktop/AIR app.
In the image below I can do steps 1) and 2) but there's a brick wall at step 3)
The problem is that simply using bitmapdata.draw(video_container); does not work but instead it throws a Policy File error even though I am using a byteArray (from local video file in the same directory as the SWF). No internet is even involved but Flash tells me that "No Policy File granted permission from the server" or such nonsense. I think the error is just a bail-out insteading of straight up saying "You are not allowed to do this.."
I have tried: trying to appease this Crossdomain.xml issue anyway and looking into all known security/domain settings. I came to the conclusion that the error is not the problem but a side effect of the issue.. The issue here being that: Flash Player is aware of the SWF's location and of any files local to it. That's okay when you pass a String as URL etc but when the Netstream data is not local to the SWF domain then it becomes a Policy File issue. Problem is my data is in the Memory not in a folder like the SWF and therefore cannot alllow bitmapData.draw since it cannot "police" an array of bytes, any known fixes for this?... (I can't even say the words I really wanted to use).
What I am trying to achieve: Is to essentially use Netstream as an H.263 or H.264 image decoder in the same way Loader is a JPEG-to-Bitmap decoder or LoadCompressed.. is an MP3-to-PCM decoder. You know, access the raw material (here RGB pixels), apply some effects functions and then send to screen or save to disk.
I know it is a little late, but I think I found a solution for your problem.
So, to avoid the Security sandbox violation #2123 Error, you have just to do like this :
// ...
net_stream.play(null);
net_stream.play('');
// ...
Hope that can help.
I know this question is a couple months old, but I wanted to post the correct answer (because I just had this problem as well and other will too).
Correct answer:
It's a bug that has been open at adobe for almost 2 years
Link to the bug on Adobe
Work Around until the bug gets fixed (I am using this and it works great):
Workaround using Sprite and graphics
To take a snapshot from a video stream we don't need NetStream.appendBytes which inject data into a NetStream object.
For that we can use BitmapData.draw which has some security constraints. That's why in many times we get a flash security error. About that, Adobe said :
"... This method is supported over RTMP in Flash Player 9.0.115.0 and later and in Adobe AIR. You can control access to streams on Flash Media Server in a server-side script. For more information, see the Client.audioSampleAccess and Client.videoSampleAccess properties in Server-Side ActionScript Language Reference for Adobe Flash Media Server. If the source object and (in the case of a Sprite or MovieClip object) all of its child objects do not come from the same domain as the caller, or are not in a content that is accessible to the caller by having called the Security.allowDomain() method, a call to the draw() throws a SecurityError exception. This restriction does not apply to AIR content in the application security sandbox. ...".
For crossdomain file creation and some other security config for AMS server, you can take a look on this post : Crossdomain Video Snapshot - Fixing BitmapData.draw() Security Sandbox Violation.
After allowing our script to get data from our video stream, we can pass to the code.
I wrote a code that play a video stream ( rtmp or http ) and take a snapshot to show it in the stage or save it as a file after applying a pixel effect :
const server:String = null; //'rtmp://localhost/vod'
const stream:String = 'stream'; // 'mp4:big_buck_bunny_480p_h264.mp4';
var nc:NetConnection;
var ns:NetStream;
var video:Video;
const jpg_quality:int = 80;
const px_size:int = 10;
nc = new NetConnection();
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, function(e:AsyncErrorEvent):void{});
nc.addEventListener(NetStatusEvent.NET_STATUS, function(e:NetStatusEvent):void{
if(e.info.code == 'NetConnection.Connect.Success'){
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, function(e:NetStatusEvent):void{});
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, function(e:AsyncErrorEvent):void{});
video = new Video(320, 180);
video.x = video.y = 10;
video.attachNetStream(ns);
addChild(video);
ns.play(stream);
}
})
nc.connect(server);
btn_show.addEventListener(
MouseEvent.CLICK,
function(e:MouseEvent): void{
var bmp:Bitmap = pixelate(video, px_size);
bmp.x = 10;
bmp.y = 220;
addChild(bmp);
}
)
btn_save.addEventListener(
MouseEvent.CLICK,
function(e:MouseEvent): void{
var bmp:Bitmap = pixelate(video, px_size);
var jpg_encoder:JPGEncoder = new JPGEncoder(80);
var jpg_stream:ByteArray = jpg_encoder.encode(bmp.bitmapData);
var file:FileReference = new FileReference();
file.save(jpg_stream, 'snapshot_'+int(ns.time)+'.jpg');
}
)
function pixelate(target:DisplayObject, px_size:uint):Bitmap {
var i:uint, j:uint = 0;
var s:uint = px_size;
var d:DisplayObject = target;
var w:uint = d.width;
var h:uint = d.height;
var bmd_src:BitmapData = new BitmapData(w, h);
bmd_src.draw(d);
var bmd_final:BitmapData = new BitmapData(w, h);
var rec:Rectangle = new Rectangle();
rec.width = rec.height = s;
for (i = 0; i < w; i += s){
for (j = 0; j < h; j += s){
rec.x = i;
rec.y = j;
bmd_final.fillRect(rec, bmd_src.getPixel32(i, j));
}
}
bmd_src.dispose();
bmd_src = null;
return new Bitmap(bmd_final);
}
Of course, this is just a simple example to show the manner to get a snapshot from a video stream, you should adapt and improve it to your needs ...
I hope all that can help you.

Actionscript(AIR) Cant return FB access_token from HTMLLoader

Im simply trying to get my users access token from FB using HTMLLoader. When i trace the output from the location change event all i get are Google/FB urls, none of which have the token.
Here is my code:
var loader:HTMLLoader;
function onChange(e:Event):void {
if(loader.location.indexOf("#") != -1) {
trace("Found token");
}else {
trace(loader.location);
}
}
function connectFb() {
loader = new HTMLLoader();
loader.addEventListener(Event.LOCATION_CHANGE, onChange);
loader.width = 640;
loader.height = 480;
loader.load(new URLRequest("https://graph.facebook.com/oauth/authorize?
client_id=1234567890123456&redirect_uri=http://google.com&type=user_agent"));
}
My Codes output:
https://graph.facebook.com/oauth/authorize?client_id=164534120383085&redirect_uri=http://google.com&type=user_agent
http://www.google.com/
I tried every tutorial on the net and even bought a book on AS3 facebook dev & still cant figure this out; Any help would be VERY appreciated since this is a fairly important project to me
From what I understand, you're trying to retrieve an oauth access token from the facebook API, right? That's what you're expecting to get back from that URL? Correct me if I'm wrong, but HTMLLoader is for (unsurprisingly) loading HTML content. If you're expecting HTML content (ie, an 'authorize' page from FB), then you need to add the HTMLLoader to the display list with:
addChild(loader); // where 'loader' is an instance of HTMLLoader
On the other hand, if you were expecting just the token (and not HTML content), then you should be using URLLoader, and not HTMLLoader.

Error #2044: Unhandled StatusEvent:. level=error, code= while sending values from child swf to parent swf

I am trying to load a game.swf into main.swf and when the game in the game.swf completes it sends the score and stars got by playing the game -to the main.swf , but the problem is the main.swf is not receiving the values and giving the above said error. Please do help..
the code in main.swf to receive score and stars is,
var receiving_lc:LocalConnection;
receiving_lc = new LocalConnection();
receiving_lc.connect("gameToEngine");
receiving_lc.client = this;
public function saveScore(score:int, stars:int):void
{
trace("score="+score.toString()+ " stars="+ stars.toString());
}
the code in game.swf to send score and stars is,
var sending_lc:LocalConnection;
sending_lc = new LocalConnection();
function send_it(evt:MouseEvent):void
{
sending_lc.send("gameToEngine", "saveScore", score, 2);
}
my_btn.addEventListener(MouseEvent.MOUSE_UP, send_it);
please help to solve this out....
GOT IT SOLVED....
with the help of fsbmain...
Just need to make the receiving_lc a global variable... hope it helps..
First, try to use domain independent local connection name, that is began with _, the _gameToEngine in your case and second add status event listener handle the StatusEvent error:
sending_lc.addEventListener(StatusEvent.STATUS, onLCStatus);
protected function onLCStatus(event:StatusEvent):void
{
trace("onLCStatus:", event.code);
}
UPD:
to prevent garbage collecting of the receiving_lc store the link to it in the private property:
private var receiving_lc:LocalConnection;