Copy link to clipboard
Copied
I have a short video of about 90 seconds that I'd like to embed in my SWF file. For some reason however my AS3 code can't find the video. I need to use the bitmapdata.draw method to take still shots of the FLV to simulate a webcam if my users don't have a webcam. I also don't want to use any components because my code takes the bitmapdata.draw from a Video class instance so I'd like to use the same methods I'm using for the webcam. I tried putting the FLV on a remote server and that worked except the bitmapdata.draw kept coming up with security violations that appear to be a bug. I'd rather have the FLV embedded anyway since its so short in length and not on a timeline so I can access it directly in Action Script.
I imported the FLV file and in the library I see the FLV with it's auto-generated MovieClip. In the output I get: Net Stat: NetStream.Play.StreamNotFound
All of the forums that I've researched talk about the FLV and the FLV Component Players, but none get this simple except Lee Brimelow's site. Hopefully it's a simple fix.
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.Event;
var my_video:Video = new Video(720,1080); //The video is taller than wider
addChild(my_video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
my_video.attachNetStream(ns);
//ns.play("http://www.postureviewer.com/video4a"); //This works and the video is still at this location.
//ns.play("Video4a.flv"); //Doesn't work
ns.play("video4a"); //Doesn't work
var netClient:Object = new Object();
netClient.onMetaData = function(meta:Object)
{
trace("Meta Duration: "+meta.duration);
};
ns.client = netClient;
ns.addEventListener(NetStatusEvent.NET_STATUS, netstat);
function netstat(stats:NetStatusEvent)
{
trace("Net Stat: "+stats.info.code);
};
you don't need to even do that if you put the flv in the same directory with your published swf. just use,
ns.play("Video4a.flv");
Copy link to clipboard
Copied
put the flv on the same server as your flash app and use a local path to the flv.
Copy link to clipboard
Copied
I'm actually writing an Adobe Air App and I'm trying to avoid having the flv on the server. I wrote this small fla producing a swf to figure out this problem.
I imported the video into my fla file. Why can't my code see it?
Copy link to clipboard
Copied
your code can access an flv embedded in a timeline. to do that conveniently, create a new movieclip and add the flv to that movieclip's timeline. ie, don't use the main timeline for your embedded flv.
also, consider that you may have problems like decreased fidelity and audio/video asynchrony.
you can then use the full range of movieclip methods and properties to control your video. but, that will be different than you're currently trying to do. in particular, whatever you're using for a screenshot will have to change.
but, if you're creating an air app, why aren't you including your flv locally (packaged with your app)?
Copy link to clipboard
Copied
Are you saying that the code written above will work correctly if I package the flv locally? I'll have to reference the flv differently using File.applicationDirectory.
But other than that I'm good to go right?
Copy link to clipboard
Copied
you don't need to even do that if you put the flv in the same directory with your published swf. just use,
ns.play("Video4a.flv");
Copy link to clipboard
Copied
That part works, but when I try to capture I get the same old security error:
SecurityError: Error #2123: Security sandbox violation: BitmapData.draw: app:/capture138_flash11_14_18_AIR_27.swf cannot access unknown URL. No policy files granted access.
at flash.display::BitmapData/draw()
This surprises me since it's in the same directory right next to the Air swf file. I understand this more with the online video, but the same bug must translate over to the local file. This simply might not work with the current bug. Any suggestions? I tried this in my bigger application, but could put it into a small app for you to view the problem.
Actually, if you look here you'll see this isn't the first time this has come up:
http://forums.adobe.com/message/5102955
In fact, they're trying a similar thing it seems. Off to the right of the page you can see other examples of this. Sounds like a dead end to me...Thoughts?
Copy link to clipboard
Copied
i don't see that problem. that could be because of flash player security settings.
to test, download http://www.kglad.com/Files/forums/test.zip
extract to a directory, install test2.air and after the video starts click the black button on the right to take a screenshot.
Copy link to clipboard
Copied
You're right, that works just fine. So what am I missing here? First I don't know how to get to the User Controls on Vista. I'm used to the old way of going to the adobe website and trusting certain websites, etc. This new method I'm lost with.Even if I could get to them, not sure what to change.
Also in my old programs using AS3 only I could get the Player Preferences dialog box to show up. Now in Air that code doesn't do anything.
Copy link to clipboard
Copied
if the files in test.zip work for you, there is no settings issue. you're doing something wrong.
download http://www.kglad.com/Files/forums/test3.fla and use the same code as i used.
Copy link to clipboard
Copied
You're absolutely right. I was doing something wrong. Turns out I was trying to pull a fast one and got caught. It's odd the way I'm doing things. I need to capture from a large video 720wide x 1080height which isn't added to the stage. I also need to display the same video on the stage at 300wide x 450height. For the webcam this was easy:
my_video.attachCamera(my_cam); (This is the large video)
my_video2.attachCamera(my_cam); (This is the small video)
But that same trick doesn't work with NetStream. Had to do this instead which works.
var my_nc:NetConnection = new NetConnection();
my_nc.connect(null);
var my_ns1:NetStream = new NetStream(my_nc);
var my_ns2:NetStream = new NetStream(my_nc);
my_video.attachNetStream(my_ns1);
my_video2.attachNetStream(my_ns2);
my_ns1.play("video4a.flv");
my_ns2.play("video4a.flv");
If I tried:
var my_ns:NetStream = new NetStream(my_nc);
my_video.attachNetStream(my_ns);
my_video2.attachNetStream(my_ns);
my_ns.play("video4a.flv");
Then it only attaches to my_video2 and nothing gets attached to my_video. This was giving me the security error.
Not sure how to make this any better. This is only for people testing my app if they don't have a webcam so normally this won't even be used. But it's important for me to have this.
Thanks a lot for your help. I never would have figured this out. I had given up.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now