• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Participant ,
Feb 09, 2023 Feb 09, 2023

Copy link to clipboard

Copied

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

Views

315

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 13, 2023 Feb 13, 2023

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 {
}

Votes

Translate

Translate
Community Expert ,
Feb 09, 2023 Feb 09, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2023 Feb 09, 2023

Copy link to clipboard

Copied

flv_pb.metadata.duration;  // in seconds

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 12, 2023 Feb 12, 2023

Copy link to clipboard

Copied

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")

}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2023 Feb 13, 2023

Copy link to clipboard

Copied

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 {
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 14, 2023 Feb 14, 2023

Copy link to clipboard

Copied

Thanks KGlad... this worked!  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2023 Feb 14, 2023

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines