如何使用带的BitmapData.draw NetStream.appendBytes? [英] How can I use BitmapData.draw with NetStream.appendBytes?
问题描述
我使用NetStream.appendBytes()来播放本地视频 Adobe AIR的(不涉及服务器)。我想用的BitmapData.draw()
带视频输出的图片,但我收到此错误:
I am using NetStream.appendBytes() to play a local video (no server involved) in Adobe AIR. I would like to use BitmapData.draw()
to take a picture of the video output, but I am getting this error:
错误#2123:安全沙箱冲突:的BitmapData.draw:无法访问空。没有策略文件授予访问权限。
Error #2123: Security sandbox violation: BitmapData.draw: cannot access null. No policy files granted access.
下面是一些示例code:
Here is some 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;
}
}
}
这是一个解释只样本code使用。调用getImage方法时,而播放视频时的错误会发生。在错误中提到找不到一个政策文件。由于加载该文件在本地没有一个真正的地方放一个策略文件。是否有需要设置或者是的BitmapData.draw
功能只是不可用时,使用一个策略设置的地方对appendBytes
?
This is only sample code use for an explanation. The error would happen when calling the getImage method while the video is playing. The error mentions a policy file not found. Since the file is loaded locally there isn't really a place to put a policy file. Is there a policy setting somewhere that needs to be set or is the BitmapData.draw
feature just not available when using appendBytes
?
推荐答案
我觉得另一种解决方案是使用 _ns.play(路径)
,而不是使用 _ns.appendBytes()
。
I think another solution is to use _ns.play(path)
and not to use _ns.appendBytes()
.
这篇关于如何使用带的BitmapData.draw NetStream.appendBytes?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!