问题
I'd like to play videos, as well as display images and possibly other flash content using adobe air, and reading from the local file system. I've been searching APIs and I have not yet been able to connect the dots.
I know of flash.filesystem.File and flash.filesystem.FileStream and have experimented with loading and reading files. I believe I can load images this way but haven't tried.
As for video:
mx.controls.VideoDisplay - seems to accept a file:// URI for source, but I can't get it to work.
flash.media.Video - accepts a NetStream or can load video directly from a video input, can't seem to find a way to reference a local file
Can anyone help me out here? I specifically want to load and play video directly off the local disk, not from a web server or a streaming file server... assume no network connectivity.
Slightly related question: Loading a video from the local file system… (but my question does not involve a web browser)
回答1:
The use I have in mind is required to be programmatic in usage. I was looking for a way to do this directly with ActionScript.
I finally stumbled onto the solution I was hoping for... using a NetStream object, but (non-intuitively) you can use this to access local files as well:
private function playVideo():void {
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
# onMetaData listener is required otherwise you get a ReferenceError
var client:Object = new Object();
client.onMetaData = function(metadata:Object):void {
trace(metadata.duration);
}
ns.client = client;
var v:Video = new Video();
v.attachNetStream(ns);
stage.addChild(v);
var f:File = new File("/tmp/test.flv");
ns.play(f.url);
}
回答2:
Try adding "-use-network=false" to your Flex compiler settings. This will give you access to load local resources, which could be the source of the problem; the sandboxing rules are somewhat sensitive, so if you're sure you won't need network connectivity, tweaking this setting might relax things a bit.
Also ran across this, which might be related as well:
http://soenkerohde.com/2008/06/playing-local-files-with-air/
In my case, though, just briefly testing, both of the following work in debug and release builds, without modifying the compiler setting, in case it's just the literals you're using to reference the FLVs:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:VideoDisplay source="D:\Data\Projects\Flex 3\AirLocalVideo\bin-debug\NightSky.flv" />
</mx:WindowedApplication>
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:VideoDisplay source="file://D:/Data/Projects/Flex 3/AirLocalVideo/bin-debug/NightSky.flv" />
</mx:WindowedApplication>
... so I guess it's maybe difficult to diagnose without a bit more information. Hope this helps -- I'll keep an eye on the comments if you want to share a bit more info.
来源:https://stackoverflow.com/questions/449369/play-video-from-local-file-using-adobe-air