Sorry for being away for a while.
It is a simple example to play .flv files from the local system. Earlier in my Jukebox tutorials I had used a fileOpen component. As the component is no more available for download, I thought of showing this alternative way to access files from local system rather than rewriting the juke box tutorials again.
I hope readers would be ablw to use this concept while building their own mp3 players.
In case there is a problem, just send me a mail (no spam, please) .
Just create a new AIR project in Flex Builder 3 and use the following code . Then click Run to see the application.
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” backgroundGradientAlphas=”[1.0, 1.0]” backgroundGradientColors=”[#FBFAFC, #F3F3F4]”>
<mx:Script>
<![CDATA[
import flash.filesystem.File;
import mx.events.FileEvent;
/*****************************
Create a file object and point it to documentsDirectory.
It is the My Documents directory in case of Windows and
Documents subdirectory of the user directory in case of Mac OS.
******************************/
private var file:File = File.documentsDirectory;
/*****************************
browseForOpen method opens up a browse directory dialog
box to open a file from My Documents directory
(Documents directory in case of Mac OS) for file browsing
and upon selection of a file onSelect method is called.
******************************/
private function fileOpen():void {
file.browseForOpen(“Select a file”);
file.addEventListener(Event.SELECT, onSelect);
}
/**********************************
onSelect method assigns the url property of the file object to the
variable vUrl and the name property to the variable vName as a string.
**********************************/
[Bindable]
private var vUrl:String;
[Bindable]
private var vName:String;
private function onSelect(event:Event):void {
vUrl = file.url;
vName = file.name;
myVideo.play();
timer.visible=true
}
private function closeVid():void {
myVideo.stop();
timer.visible=false;
vidName.visible=false;
}
]]>
</mx:Script>
<mx:VideoDisplay x=”70″ y=”26″ width=”379″ height=”234″ id=”myVideo” source=”{vUrl}”/>
<mx:Button click=”fileOpen()” label=”Open” x=”70″ y=”289″/>
<mx:Button x=”134″ y=”289″ label=”Close” click=”closeVid()”/>
<mx:Label x=”90″ y=”10″ text=”{vName}” id=”vidName” fontSize=”10″ fontWeight=”bold” color=”#0E5B87″/>
<mx:Label x=”210″ y=”291″ id=”timer” text=”{myVideo.playheadTime}/{myVideo.totalTime}” visible=”false”/>
</mx:WindowedApplication>
If everything is OK and the application works, then start packaging for distribution.
With release of next version of Flash Player, You will be able to create your own media player . Future seems so bright.
8 comments
Comments feed for this article
August 24, 2007 at 6:55 am
Build MP3 players in AIR | Adobe AIR Tutorials
[…] learn more @ https://flnotes.wordpress.com/2007/08/23/flv-player-in-air-beta-using-flex-3/ […]
August 24, 2007 at 3:02 pm
Flex FLV Player on AIR | reintroducing.com Blogging Receptacle
[…] Here’s a short tutorial on how to build an FLV player in AIR using Flex 3. […]
August 29, 2007 at 4:40 pm
Alex Popa
A question i have if is possible. I have to do an application using flex 3 and this app has to capture the screen when a button is pressed and then upload it to a server.
This is possible? If yes, how?
Thanks.
December 31, 2007 at 4:29 am
pythagoras1
I don’t see a live sample … (unless I’m just really tired) I’m not going to bother going through your tut, unless i see a sample first to see if it’ worth it..
January 21, 2008 at 5:19 pm
rahul
hi great work sir…..
February 11, 2008 at 7:33 am
Ari
Nice – this is exactly what I’ve been looking for…
February 25, 2008 at 8:13 am
Pratap
HI
when i try to use this code am facing some problem over here…
like —
Definition flash.filesystem:File could not be found
can u tell me y its happening like this???
Thanks & REgards
PRatap
February 29, 2008 at 4:02 am
flnotes
@Pratap
without looking into your code, my best guess is maybe
import flash.filesystem.File; is missing.
If this is not the case then send me your code through mail(ashwinee2004[AT]gmail[DOT]com), i will look at it.
BTW recently i have tried this code in the Flex Builder 3 and AIR 1.0 and it works.
@Alex
Screen capture is not possible. For more details and discussions please follow https://flnotes.wordpress.com/2007/09/01/will-adobe-let-us-create-a-screen-capture-application-in-air/