载入中AIR的图像和视频,而HTTP [英] loading images and video in AIR without HTTP
问题描述
我很好奇,正确的方法是用于加载图像和视频直接从文件系统中的数据,不使用HTTP。
I'm curious what the correct methodology is for loading image and video data directly from the file system, without employing HTTP.
我在写一个AIR幻灯片应用程序,它的伟大工程,但目前依赖本地MAMP服务器上交出的应用程序通过标准的所有媒体,屡试不爽,闪存介质加载方法。
I'm writing an AIR slideshow application, and it works great but currently relies on a local MAMP server to hand the app all the media via the standard, tried and true, FLASH media loading methodologies.
我知道,由于Flash是作为一个Web插件它处理这种方式接收数据最好的,但我真的很喜欢但是自拔这个相当繁琐和不必要的位,并有应用程序作为一个独立的播放器,我不清楚正确的方法是什么,无法加载介质。
I know that since FLASH was developed as a web plugin it handles this way of receiving data best, but I'd really like to extricate this rather onerous and unnecessary bit and have the app as a stand-alone player, however, I'm unclear what the "correct" way is to load the media.
我有一个文件对象做好准备,我已经尽量让用户选择要拉媒体和我得到的文件从列表中的列表(基于扩展名)的本地目录得到。 ..但现在该怎么办?
I have the File objects ready and I've gotten as far as having the user select the local directory from which to pull the media and I'm getting a list of the files (based on their extensions) from the list... but now what?
推荐答案
您首先必须把你的文件的内容从的ByteArray
(code <一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html#readBytes%28%29"相对=nofollow> 的FileStream
文档)
You first have to put the content of your file in a ByteArray
(code from FileStream
documentation)
var bytes:ByteArray = new ByteArray();
var myFileStream:FileStream = new FileStream();
var myFile:File = File.documentsDirectory.resolvePath("test.jpg");
myFileStream.addEventListener(ProgressEvent.PROGRESS, progressHandler);
myFileStream.openAsync(myFile, FileMode.READ);
function progressHandler(event:ProgressEvent):void
{
if (myFileStream.bytesAvailable)
{
myFileStream.readBytes(bytes, myFileStream.position, myFileStream.bytesAvailable);
}
else
{
myFileStream.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
loadImage();
}
}
然后你可以在装载机
来显示图像(见方法加载这些字节<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#loadBytes%28%29"相对=nofollow> Loader.loadBytes
)
Then you may load these bytes in a Loader
to display the image (see method Loader.loadBytes
)
function loadImage():void
{
var loader:Loader = new Loader();
loader.loadBytes(bytes);
addChild(loader);
}
干杯
这篇关于载入中AIR的图像和视频,而HTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!