I have written an AIR Application that downloads videos and documents from a server. The videos play inside of the application, but I would like the user to be able to open the documents in their native applications.
I am looking for a way to prompt the user to Open / Save As on a local file stored in the Application Storage Directory. I have tried using the FileReference + URLRequest classes but this throws an exception that it needs a remote url.
My last resort is just copying the file to their desktop : \
You can use the new openWithDefaultApplication(); function that's available on the File class (I believe it's only available in AIR 2)
eg:
var file:File = File.desktopDirectory.resolvePath(fileLocation);
file.openWithDefaultApplication();
Only way I could figure out how to do it without just moving the file and telling the user was to pass it off to the browser.
navigateToURL(new URLRequest(File.applicationStorageDirectory.nativePath + "/courses/" + fileName));
This is the first release of the FluorineFx Aperture framework.
The framework provides native OS integration (Windows only) support for AIR desktop applications.
The framework extends Adobe AIR applications in a non-intrusive way: simply redistribute the provided libraries with your AIR application, at runtime the framework will automatically hook into your application.
Features
Launch native applications and documents with the provided apsystem library
Take screenshots of the whole screen with the provided apimaging library
Access Outlook contacts from an Air application with the provided apoutlook library
http://aperture.fluorinefx.com/
Currently adobe is not supporting opening files in there default applications. Passing it off to the browser seems to be the only way to make it work.
You could however use a FileStream and write a small html file with some javascript that sets the location of an iframe to the file, then after 100ms or so calls window.close(). Then open that file in the browser.
For me it's:
var request:URLRequest = new URLRequest();
request.url = file.url;
navigateToURL(request, "_blank");
The navigateToURL(file.nativePath) didn't work since the path, "/users/mydirectory/..." was outside the application sandbox. AIR only allows some protocols to be opened with navigateToURL().
Related
I'm trying to run my flex application in the air runtime instead of flash runtime. It seems to work perfectly except the images. Adobe Air runtime tries to load them. Is there a way to change the root adresses for Image to server side? If possible I'd like to use the same code for flash runtime and air runtime .. "single codebase ;-)"
var icon:Image = new Image();
icon.source = "images/test.png";
regards
cyrill
Typically I would simply package the assets into the AIR app. That way the relative paths would be valid both in the web app and the desktop app. However, since you pointed out in the comments that we're talking 10000 images you'll have to find another solution.
What you need is a variable that is configurable for each type of project. The final code to access your images should look like:
var icon:Image = new Image();
icon.source = rootUrl + "/images/test.png";
That rootUrl may be "" for the web app, and "http://www.mydomain.com" for the desktop app. Or it could be the absolute path in both cases. It doesn't matter: we don't want to hardcode that URL into our application.
Create a .properties file (or XML, or JSON; whatever configuration file you like) that contains the value for rootUrl and read that into your application model. This configuration file can be packaged into the AIR app.
A .properties file will look like this:
#myapp.properties
rootUrl=http://www.mydomain.com
For reading the file, you could use AIR's file streaming capabilities, but I suggest you load it the old-fashioned way with a URLLoader: this way it'll work both in the web and the desktop app.
So I created an ASP.NET 4 application in VS2010, that needs to play sound to the end user, and it is working perfectly in my local development environment. The problem is the sound resource nor the Resources.resx is not being published to the server. Any idea why?
What I did:
1) Under Project Properties Recources I added my sound resource called: soundbyte (containing soundbyte.wav). I noticed this creates a Resource folder with the wav file and under my project a Resources.resx file referencing the file
2) In my code I play the file as follows:
Dim audioFile = My.Resources. soundbyte
Dim player = New Media.SoundPlayer(audioFile)
player.Load()
player.Play()
In the Visual Studio Solution Explorer right-click on Resources.resx and select Properties. Build Action. Set to content.
EDIT: The following resource might also help.
http://blog.andreloker.de/post/2010/07/02/Visual-Studio-default-build-action-for-non-default-file-types.aspx
Ultimately, I found a way to play the sound to the client browser (as opposed to the server the asp app is running on) was to follow the techniques in this example: http://www.vbdotnetheaven.com/UploadFile/scottlysle/PlaySoundsInASPX09032006083212AM/PlaySoundsInASPX.aspx
But I found an even better way in my case was to use Javascript, which doesnt' require the Resources technique.
simply embed the sound on the page after the tag:
<embed src="Sounds/jump.wav" autostart=false width=1 height=1 id="sound1" enablejavascript="true">
Then in javascript setup the function:
function EvalSound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.Play();
}
Finally play the sound in the browser as needed in Javascript:
EvalSound('sound1');
I'm in the early stages of creating a MFT to decode a "new" container format video. I'm using the MPEG1Source sample from the Media Foundation SDK, and I have a mpeg1 sample. I changed the extensions in both to ".test" and registered the dll.
Windows Media Player can open the file (my breakpoints are hit and the video plays), but Windows Media Center doesn't- opening from the command line works when the file is .mpg, but not as .test. My breakpoints aren't hit; it doesn't look like it even tries to load the dll (Visual Studio doesn't report my dll being loaded in the output window).
This is 64-bit Windows 7; the dll is native 64-bit.
Is there some additional registration that needs to happen before Media Center will understand a new file type?
I tried using MFTrace to trace the Media Foundation calls- nothing
I tried using Event Viewer to trace Media Foundation- nothing
Finally, I tried Process Monitor- great success! Media Center does a registry scan of HKCU\Software\Classes\.test, HKCR\.test, etc, and looks for a key called "PerceivedType"- if it's "video", then it will play.
So I added the registry key HKEY_CLASSES_ROOT\.test\PerceivedType = video and it works!
I am working with a very large number of legacy SWFs written in AS1 and AS2. These SWFs use loadMovieNum extensively.
I am trying to integrate these into a new Air-based app (written in either AS3 or Flex). However, loadMovieNum doesn't seem to work within the Air app.
For example, an AS2 SWF (file1.swf) may try to load another AS2 SWF using:
loadMovieNum("http://127.0.0.1/file2.swf", 5);
This works fine if the SWF is played indepedently but if it is played from within the Air app, it fails.
EDIT: What happens in the Air app is that file1.swf will load successfully but silently fails to load file2.swf. There are no errors and no exceptions. A try...catch around the loadMovieNum reports nothing and file1.swf continues to play.
The relevent code from the Air app is as follows:
AS3 version:
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("http://127.0.0.1/file1.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.load(mRequest, loaderContext);
function onCompleteHandler(loadEvent:Event):void
{
// Add to the stage
addChild(mLoader.content.parent);
}
Flex version:
<mx:SWFLoader id="swfObj" source="http://127.0.0.1/file1.swf" />
It is simply the case that loadMovieNum will not work in Air? Or is there something that can be done. Obviously, making extensive changes to the legacy SWFs is, in all liklihood, not possible.
Thanks in advance.
I've concluded that _levels are not supported in SWFs that are loaded directly into Air apps. For example, even _level0 (which should always be defined) returns as undefined. Consequently, it would appear very unlikely that loadMovieNum would be supported.
I have discovered a workaround, though. Using the HTML browser component in Air, a webpage - in which the AS2/1 SWFs are embedded - can be loaded into the Air app. If you do this then loadMovieNum works as expected in the AS2/1 files.
AS3 version:
var hLoader:HTMLLoader = new HTMLLoader();
addChild(hLoader);
hLoader.width = stage.stageWidth;
hLoader.height = stage.stageHeight;
hLoader.load(new URLRequest("file1.html"));
Flex version:
<mx:HTML id="minibrowser" width="100%" height="100%" location="file1.html" />
Unfortunately, the HTML component is not supported by all Air profiles. In particular, in my case, it is not supported by the TV profile.
Although it may not seem intuitive, this seems like a security issue. When AS2 content loads up other AS2 content, they have to be in the same security sandbox in order for them to run.
I created a quick sample just to test this theory and I was right. The reason it works in Flash is because the AS2 content is in the same sandbox as the content it is loading. But AIR security is different. So when you load up the AS2 content in AIR (using the logic you supplied), the loader gets put in the application sandbox. The sandbox is now different than the content it is loading, so it refuses to load them.
This explains why it works when using an HTML wrapper. When the HTML loads up the swf, it probably gets put in the local-with-network sandbox which is the same as the content.
So... How do you fix it?
You can try to load your content up in a different security sandbox. But really the problem is that AS3 security isn't playing nice with the AS2 security. My suggestion would be to create the AIR application without an AS3 wrapper. You can't do this directly in the tooling, but you should be able to use the ADT packager to do it. In the xml descriptor, make the initial content the AS2 swf, and package it together. Now when you launch your AIR application it uses the AS2 swf as the main application. Suddenly your files should all be in the same security sandbox, and Flash won't prevent any of the content from running.
You can test this locally by using ADL to launch the app instead of launching it directly from Flash Professional or Flash Builder. (They both use ADL, but if you call it directly you have more control over the arguments used.)
EDIT: Apparently you can't have an AS2 swf as the main swf for Desktop AIR applications. (I've tested using ADL on desktop and it works, but I have been told that you won't be able to install an AIR application on desktop with this setup.) So for desktop you probably want to use the HTML workaround. This is supported in AIR for TV, so this would work on those devices.
OK I know that in Adobe Air you can call navigateToURL(new URLRequest(url)) and it will open the users default web browser to open the page.
Also now in AIR 2 you can launch any application.
So I am wondering if there is a way I can launch a particular browser to open a page in?
I it turns out with AIR 2 you can run command ling arguments so I was able to achieve what I wanted like so:
private function openApp():void
{
if(NativeProcess.isSupported)
{
var file:File = File.userDirectory;
file = file.resolvePath("AppData/Local/Google/Chrome/Application/chrome.exe");
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
var process:NativeProcess = new NativeProcess();
var args:Vector.<String> = new Vector.<String>();
args.push("https://www.google.com");
nativeProcessStartupInfo.arguments = args;
process.start(nativeProcessStartupInfo);
}
}
If you're using navigateToURL it, basically, passes the URL to the operating system and opens the default application for handling such requests. You can use navigateToURL to open word documents and other files too.
I was pretty sure that the NativeProcess features of AIR 2 allow you to launch applications, but I did not believe they allow you introspect the system to discover what browsers exist and where the DLL / EXE files are.
A good article on the native process stuff: http://www.adobe.com/devnet/air/flex/quickstart/interacting_with_native_process_02.html