How can I make a dynamic video player in Actionscript 3.0 in Flash

620 Views Asked by At

Need a video player code in Actionscript 3. It is possible to play mp4 format video from any folder in my phone storage location ?

1

There are 1 best solutions below

1
On

Since it's for mobile (using AIR), try using the File class. It allows you to browse for files.
You can lock the file browsing to list only specific format(s) by using FileFilter.

Read the Adobe guide here : Working with File objects in AIR.

Below is an example code you can try. Untested at moment (but modified from this other Answer).

//someGraphic is your own UI element (clicked/tapped) for user to begin file browse
someGraphic.addEventListener(MouseEvent.CLICK, browseVideo);

function browseVideo(evt:MouseEvent = null):void 
{
    var vidFiles : FileFilter = new FileFilter("Choose Video", " *.mp4 ; *.flv");

    var file:File = new File();
    file.addEventListener(Event.SELECT, onFileSelected); 
    file.browse([vidFiles]);
}

function onFileSelected(evt:Event):void 
{
    //auto-extract path to give to NS video player
    playVideo(evt.currentTarget.nativePath);
}

function playVideo(video_path:String):void
{
    // using a Video + NetStream object
    var nc:NetConnection = new NetConnection();
    nc.connect(null);
    var ns:NetStream = new NetStream(nc);
    ns.client = this;
    var video:Video = new Video();
    video.attachNetStream(ns);
    addChild(video);

    ns.play(video_path); //is using auto-extracted path
}