Skip to main content
Inspiring
Feb 9, 2023 9:26 PM UTC
Answered

Function that returns the length of a video file in frames & seconds

Hello all and thanks in advance for any help you can lend.  

 

I frequently use the VideoPlaybackComponent to play videos in my projectors... In this instance, I'm wanting to dynamically select a movie file and I need the script to return the length of an assigned video file.

 

I'm struggling to find a method to do this... 

 

Thanks!

 

Erik

    This topic is closed to new replies. Start a new post to keep the conversation going.
    kglad
    kgladCorrect answer
    Community Expert
    Feb 13, 2023 3:40 PM UTC

    with netstream use this:

     

    var clientObj:Object = new Object(); 
    clientObj.onMetaData = ns_onMetaData; 
    ns.client = clientObj;



    function ns_onMetaData(metaD:Object):void {
    trace(metaD.duration)
    }

    ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

    function asyncErrorHandler(e:AsyncErrorEvent):void {
    }

    6 replies

    kglad
    Community Expert
    Community Expert
    Feb 9, 2023 10:19 PM UTC

    flv_pb.metadata.duration;  // in seconds

    flv_pb.metadata.duration*stage.frameRate;  // in frames

    Translate
    Inspiring
    Feb 13, 2023 12:29 AM UTC

    Kglad, thanks for jumping in on this.

     

    I'm still struggling to get the script to return metadata for any parameters... The video loads and plays OK.  But I'm getting the following error re: metadata:

     

    "Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onMetaData. error=ReferenceError: Error #1069: Property onMetaData not found on flash.net.NetStream and there is no default value. at testingNetstream_fla::MainTimeline/frame1()".   

     

     I'll share the basic code I'm experimenting with using NetConnect/NetStream to load and play a video file:

     

    var nc:NetConnection = new NetConnection();
    nc.connect(null);

     

    var vid:Video = new Video();

    addChild(vid);

     

    var ns:NetStream = new NetStream(nc);

    vid.attachNetStream(ns);

     

    ns.play("qt_1880-516.mov"); //my local video file

     

    function ns_onMetaData(item:Object):void {
    trace("ns.metadata.duration")

    }

     

    Translate
    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    Feb 13, 2023 3:40 PM UTC

    with netstream use this:

     

    var clientObj:Object = new Object(); 
    clientObj.onMetaData = ns_onMetaData; 
    ns.client = clientObj;



    function ns_onMetaData(metaD:Object):void {
    trace(metaD.duration)
    }

    ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

    function asyncErrorHandler(e:AsyncErrorEvent):void {
    }

    Translate
    Community Expert
    Feb 9, 2023 9:45 PM UTC

    @kglad and JoãoCésar are pretty good with code they might help you. 

    Translate