Flex Examples
Viewing an FLV video’s metadata using a Flex VideoDisplay control
The following example shows how you can use the new metadataReceived event in Flex 3 to easily grab the metadata from an FLV file.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/15/viewing-an-flv-videos-metadata-using-a-flex-videodisplay-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.events.MetadataEvent;
import mx.utils.ObjectUtil;
private const VIDEO_URL:String = "http://www.helpexamples.com/flash/video/cuepoints.flv";
private function videoDisplay_metadataReceived(evt:MetadataEvent):void {
var arr:Array = [];
var item:String;
var meta:Object = evt.info; // videoDisplay.metadata;
var value:*;
for (item in meta) {
if (ObjectUtil.isSimple(meta[item])) {
if (meta[item] is Array) {
value = "[Array]";
} else {
value = meta[item]
}
arr.push({name:item, value:value});
}
}
arr.sortOn("name", Array.CASEINSENSITIVE);
dataGrid.dataProvider = arr;
dataGrid.visible = true;
}
]]>
</mx:Script>
<mx:Button label="Click here to load video"
click="videoDisplay.source = VIDEO_URL;" />
<mx:VideoDisplay id="videoDisplay"
visible="false"
ready="videoDisplay.visible = true;"
metadataReceived="videoDisplay_metadataReceived(event);" />
<mx:DataGrid id="dataGrid"
visible="false"
width="100%"
height="100%" >
<mx:columns>
<mx:DataGridColumn dataField="name"
headerText="Name:"
sortable="false" />
<mx:DataGridColumn dataField="value"
headerText="Value:"
sortable="false" />
</mx:columns>
</mx:DataGrid>
</mx:Application>
View source is enabled in the following example.
Peter deHaan
Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
17 Responses to Viewing an FLV video’s metadata using a Flex VideoDisplay control
Leave a Reply Cancel reply
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


humm…got error. I amusing Flex 2.01
Cannot resolve attribute ‘metadataReceived’ for component type mx.controls.VideoDisplay.
metadataReceived=”videoDisplay_metadataReceived(event);” />
got, it only work in Flex 3.
Hi,
you seem to know a lot about flex and actionscript programming. I’ve been looking everywhere, but still haven’t found a working solution to this problem:
Flex 3 with Flash Player 9 supports h.264 encoded video. But VideoDisplay doesn’t? How should I program this?
I’ll be sooo grateful if you can help me find the answer!
Vegard,
Honestly, I haven’t tried H.264 w/ Flex yet, but it is high on my list of things to try. I haven’t verified anything, but I’d recommend starting with downloading the latest version of the Flex 3 Beta SDK from http://labs.adobe.com/technologies/flex/sdk/flex3sdk.html and see if there have been any edits to the VideoDisplay component.
Sorry,
Peter
I same error “mx.controls.VideoDisplay”
I compling flex3 beta..
why??
I work this..
D:4.Language\__SDK\flex3sdk_b1_061107\bin>mxmlc -version
Version 3.0 build 172357
D:4.Language\__SDK\flex3sdk_b1_061107\bin>mxmlc D:4.Language\Flex\Source\blo
g.flexexamples.com\viewing_an_flv_videos_metadata_using_a_flex_videodisplay_control.mxml
Loading configuration file D:4.Language\__SDK\flex3sdk_b1_061107\frameworks\flex-config.xml
This beta will expire on Wed Oct 31 00:00:00 KST 2007.
D:4.Language\Flex\Source\blog.flexexamples.com\viewing_an_flv_videos_metadata_
using_a_flex_videodisplay_control.mxml(43): Error: Cannot resolve attribute ‘metadataReceiv
ed’ for component type mx.controls.VideoDisplay.
metadataReceived=”videoDisplay_metadataReceived(event);” />
kan,
The
metadataReceived event must have been added in a newer version. I'm not sure exactly which build, but try grabbing a newer nightly build from the Adobe Labs site at http://labs.adobe.com/technologies/flex/sdk/flex3sdk.html.Peter
I have the latest version and Still doesn’t work properly…
Severity and Description Path Resource Location Creation Time Id
Cannot resolve attribute ‘metadataReceived’ for component type mx.controls.VideoDisplay. documentos uno.mxml line 43 1190053854082 7932
have any idea???
Rafael,
I built a simple test case and it seems to be working for me in build 182505. Do you know which exact version of the SDK you’re using? If not, you can find out by typing “mxmlc -version” in your target /bin/ directory.
<?xml version="1.0" encoding="utf-8"?> <!-- Flex 3 Nightly 182505 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"> <mx:Script> <![CDATA[ import mx.events.MetadataEvent; private function videoDisplay_metadataReceived(evt:MetadataEvent):void { lbl.text = evt.type; } ]]> </mx:Script> <mx:VideoDisplay id="videoDisplay" source="http://www.helpexamples.com/flash/video/cuepoints.flv" metadataReceived="videoDisplay_metadataReceived(event);" /> <mx:Label id="lbl" text="--default--" /> </mx:Application>Just to keep it in mind, if the flv don’t have metadata the metadataReceived event wont be triggered. so, it depends on the flv file as well…
it will be nice a way to figure that out ( if the file has metadata or not )
If you’re using Flex 2, don’t define the metadataReceived event in mxml, define it through ActionScript instead.
The VideoDisplay class is missing the Event tag
[Event(name="metadataReceived")]
So when defining metadataReceived through mxml you’ll get an error that no such method exists, allthough it is being dispatched. Adding it through ActionScript in a Script block works fine:
myVideo.addEventListener(“metadataReceived”, metadataReceivedHandler);
I’m also not clear on why you use an Array to store the metadata data. I’d use an Object instead and also not exclude nested Array and Object data. For instance, when using Burak’s metadata injector, data is added with keyframe timestamps that can be used to stream video through PHP or Coldfusion:
http://www.buraks.com/flvmdi/
http://www.realitystorm.com/experiments/flash/streamingFLV/
http://www.flashcomguru.com/index.cfm/2005/11/2/Streaming-flv-video-via-PHP-take-two
In your example that data is discarded.
Here’s what I’m currently using instead:
var obj:Object = {}; var item:String; // videoDisplay.metadata; var meta:Object = evt.info; var value:*; for (item in meta) { if (meta[item] is Array) { value = ArrayUtil.toArray(meta[item]); }else{ value = meta[item] } obj[item] = value; } trace(ObjectUtil.toString(obj));Hi! Many thanks to you, that it’s exactly what I am looking for since some days, before I looped until I have video.metadata != null in a ENTER_FRAME event handler ;-( very dirty !!! Strange that Adobe did not integrate it since Flex 2.0, like for smoothing property which is not available for VideoDisplay and Image controls (yes I know that can be fixed with mx_internal …) but why Adobe doesn’t make them available ???
Tom,
Yeah, I’m not sure how many fixes get back-ported to the Flex 201 framework. I don’t suspect too many (we’re more focused on Flex 3 at the moment, naturally).
As for VideoDisplay.smoothing, I know it has been mentioned/requested before. You may want to search the public Flex bug base at http://bugs.adobe.com/flex/ and file a bug report/feature request if there isn’t one already.
In fact, now is a great time to file any bugs/enhancement requests you may have. With Flex 3 development slowing down, Flex 4 planning is starting.
Regards,
Peter
Peter,
I have a question about metadatareceived event: I load 2 videos sequentially, and before that I add an event listener at my video control: video.addEventListener(MetadataEvent.METADATA_RECEIVED, handlerMetadataReceived);, then I load the first video, ok handler is called, but when I load the second, handler is never called!!!
Maybe handler needs to be added twice??
Best,
Tom
Very strange … seem to be a bug! Instead of metadatareceived event I use this code:
private function handlerMetadataReceived (event:Event):void {
if (video.metadata != null) {
trace ("Meta received! " video.totalTime "\n");
this.removeEventListener(Event.ENTER_FRAME,handlerMetadataReceived);
}
}
And when I load a new source of video:
video.source = this.getVideoUrl(value.video,0,this._sessionID, this._userBP);
video.load();
this.addEventListener(Event.ENTER_FRAME, handlerMetadataReceived);
Video is a VideoDisplay object. Works good for me, Is anyone could try to show 2 videos sequentially and load metadata?
Oups!! I am sorry for my last couple of comments, actually I set autoPlay to false and now metadatareceived is dispatched for my 2 videos ;-)
hellow i am alvi,
this is nice blog i ever visit. keep it more up. thanks
Once again, you made my day. Thanks for the FLV metadata tip. :)