How can I use BitmapData.draw with NetStream.appendBytes?

I use NetStream.appendBytes () to play local video (without server involvement) in Adobe AIR . I would like to use BitmapData.draw() to take a snapshot of the video output, but I get this error:

Error # 2123: sandbox security violation: BitmapData.draw: cannot access null. There are no policy files that provide access.

Here is a sample code:

 package { import flash.display.Sprite; import flash.filesystem.File; import flash.filesystem.FileMode; import flash.filesystem.FileStream; import flash.media.Video; import flash.net.NetConnection; import flash.net.NetStream; import flash.net.NetStreamAppendBytesAction; import flash.utils.ByteArray; import flash.display.BitmapData; class ByteArrayPlayer extends Sprite { private var _ns:NetStream; private var _nc:NetConnection; private var _video:Video; public function playVideo(path:String):void { _nc = new NetConnection(); _nc.connect(null); _ns = new NetStream(_nc); _video = new Video(); addChild(_video); _video.attachNetStream(_ns); _ns.play(null); _ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN); var file:File = new File(path); var fileStream:FileStream = new FileStream(); fileStream.open(file, FileMode.READ); var bytes:ByteArray = new ByteArray(); fileStream.readBytes(bytes); _ns.appendBytes(bytes); } public function getImage(video:Video):BitmapData { var bit:BitmapData = new BitmapData(_video.width, _video.height); bit.draw(_video); //This will cause the error return bit; } } } 

This is just an example of using code for explanation. An error occurred while calling the getImage method during video playback. The error mentions a policy file that was not found. Since the file is downloaded locally, there really is no place to host the policy file. Is there a policy setting somewhere that needs to be set, or is the BitmapData.draw function just not available when using appendBytes ?

+8
flash actionscript-3 air adobe flash-video
source share
7 answers

I think another solution is to use _ns.play(path) and not use _ns.appendBytes() .

+1
source share

Try setting NetStream.checkPolicyFile = true before you call the play() function.

Like this:

 _ns.checkPolicyFile = true; _ns.play(null); 

What the checkPolicyFile flag means is that it tells the swf host to download the policy file from the loaded SWF server. If you did not specify this flag at boot time, you will receive a SecurityError when you try to get pixel data from the downloaded stream through BitmapData.draw() .

Adobe resource link: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#checkPolicyFile

0
source share

Ive decided to get rid of the sandbox error while trying to draw the content of netstream.appendByte() .

SWF retrieves the sandbox because it searches for the crossdomain file at the address you specify :netstream.play(null) . Hes is looking for something that does not exist.

Well, the solution is to play a fake video, for example " netstream.play(http://myserv.com/video.flv) " with the original crossdomain file on it, and after that you just need to download the video you want , thanks to the appendBytes function.

SWF tricked!

Oddly enough, this works for me :-)

0
source share

You cannot take a video or audio snapshot from the rtmp stream if the server-side parameters called StreamVideoSampleAccess or StreamAudioSampleAccess are not set to true or set to this StreamVideoSampleAccess / StramVideoSampleAccess. I did not find a way to do this without access to the FMS server.

0
source share

Try placing the Video object in MovieClip and using bit.draw(_movieclipInstanceName); instead of a video object. I hope this works.

0
source share

I know this question is really old ... but it is still a problem that I ran into, and I know that others will also ... Therefore, I wanted to post a link to another question on Stack, where I posted an error in Adobe and a workaround to make it work.

Workaround for error in duplicate question stack

0
source share

It looks like you are trying to call the BitmapData.draw () method for a video that is not loaded, or when the NetStream object is null.

possible fix: before sending NetStream.Buffer.Full NetStatus before calling draw ()

-one
source share

All Articles