December 19, 2007 6:13 PM
AIR allows developers to write in HTML and Javascript by simply setting the content tag in the application descriptor file to the HTML file you created. This approach to AIR deprives you of all the cool Flex components like VideoDisplay where you can just set the source to play the movie; but it does allow people familiar with HTML to code in AIR without learning a new language.

Playing Video in AIR using HTML and Javascript is not that simple. But it isn't that hard either.

The HTML snippet below plays FLV and H.264 encoded quicktime movies.

Update (20th December 2007): Make sure you have AIRAliases.js in the same folder as your html file. It has to be copied over from AIR SDK installation folder/frameworks. AIRAliases.js only comes with the AIR SDK. It doesn't come with Flex Builder or Flex SDK because Flex Builder doesn't yet support launching HTML AIR applications directly. AIRAliases.js just shortens long names for convenience.

Just change sample.flv to the appropriate flv or quicktime movie file.

<html>
<head>
<title>Test</title>
<script src="AIRAliases.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
var nc = new air.NetConnection()
nc.connect(null);
var ns = new air.NetStream(nc);
ns.addEventListener(air.AsyncErrorEvent.ASYNC_ERROR, asyncError);
function asyncError()
{
//handle error here
}
ns.play("sample.flv");
var vid = new air.Video();
vid.attachNetStream(ns);
window.htmlLoader.stage.addChild(vid);
</script>
</body>
</html>

Couple the HTML file with the application descriptor file:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://ns.adobe.com/air/application/1.0.M6">
  <id>AirApp</id>
  <filename>AirApp</filename>
  <version>v1</version>
  <initialWindow>
    <content>test.html</content>
    <visible>true</visible>
    <width>400</width>
    <height>400</height>
  </initialWindow>
  <name>AirApp</name>
</application>

If the AIR application HTML file was named test.html and the application descriptor was saved as AirApp-app.xml, you can launch this application by typing the following command at the command prompt:

adl AirApp-app.xml

Presto, a simple application that plays videos. Not bad for the amount of functionality you get in 22 lines of code, eh?

CategoryAIR Comment(s)

Copyright © 2004-2011 Anirudh Sasikumar. All rights reserved.
Last Updated: January 14, 2008 8:00 PM