07Apr

Video Player with XML and the FLVPlayback and DataGrid Components

2 comments so far

I just created a simple video player. I wanted the data grid component to hold a description of the videos in the xml file as well as display the thumbnail image for the movies. In addition to this there is the ability to link to a specified Skin movie to apply to the video player. Here are a few sites of the classes that I used:

http://www.adobe.com/devnet/flash/quickstart/datagrid_pt3/#section14

http://www.communitymx.com/content/article.cfm?cid=88033

The XML files holds the location of the thumbnail image, the location of the .flv movie and a description node for a description of the movie. An example of the xml is:

<rss>
<channel>
<item>
<thumbnail>/path/to/thumbnail.jpg</thumbnail><flvurl>/path/to/flvmovie.flv</flvurl>
<description>Here is my description</description>
</item>
<item>
<thumbnail>/path/to/thumbnail.jpg</thumbnail><flvurl>/path/to/flvmovie.flv</flvurl>
<description>Here is my description</description>
</item>
</channel>
</rss>

Here is the main document class used:

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLLoader;
    import flash.net.URLRequest;
	import fl.controls.DataGrid;
	import fl.controls.dataGridClasses.DataGridColumn;
	import fl.data.DataProvider;

	public class Main extends Sprite
	{
		private var myDataGrid:DataGrid = new DataGrid();
        private var dp:DataProvider;
		private var xml:XML;
		private var fpp:FLVPlaybackPro = new FLVPlaybackPro();

		public function Main()
		{
			var loader:URLLoader = new URLLoader();
            loader.addEventListener(Event.COMPLETE, DataGridLoad);
            loader.load(new URLRequest("/path/to/xml/file.xml"));
		}

		private function DataGridLoad(e:Event):void
		{
			xml = new XML(e.target.data);
			var il:XMLList = xml.channel.item;

			var dp:DataProvider = new DataProvider();

			for (var i:uint=0; i

The FLVPlaybackPro

package {

    import fl.video.FLVPlayback;

    public class FLVPlaybackPro extends FLVPlayback {

       public function FLVPlaybackPro(){
          super();
       }
    }
}

The cell renderer class for the data grid component used:

package {
    // Import the required component classes.
    import fl.containers.UILoader;
    import fl.controls.listClasses.ICellRenderer;
    import fl.controls.listClasses.ListData;
    import fl.core.InvalidationType;
    import fl.data.DataProvider;
    import flash.events.Event;

    /**
     * This class creates a custom cell renderer which displays an image in a cell.
     * Make sure the class is marked "public" and in the case of our custom cell renderer,
     * extends the UILoader class and implements the ICellRenderer interface.
     */
    public class LoaderCellRenderer extends UILoader implements ICellRenderer {
        protected var _data:Object;
        protected var _listData:ListData;
        protected var _selected:Boolean;

        /**
         * Constructor.
         */
        public function LoaderCellRenderer():void {
            super();
        }

        /**
         * Gets or sets the cell's internal _data property.
         */
        public function get data():Object {
            return _data;
        }
        /**
         * @private (setter)
         */
        public function set data(value:Object):void {
            _data = value;
            source = value.data;
        }

        /**
         * Gets or sets the cell's internal _listData property.
         */
        public function get listData():ListData {
            return _listData;
        }
        /**
         * @private (setter)
         */
        public function set listData(value:ListData):void {
            _listData = value;
            invalidate(InvalidationType.DATA);
            invalidate(InvalidationType.STATE);
        }

        /**
         * Gets or sets the cell's internal _selected property.
         */
        public function get selected():Boolean {
            return _selected;
        }
        /**
         * @private (setter)
         */
        public function set selected(value:Boolean):void {
            _selected = value;
            invalidate(InvalidationType.STATE);
        }

        /**
         * Sets the internal mouse state.
         */
        public function setMouseState(state:String):void {
        }
    }
}

Share/Save/Bookmark

Monday, April 7th, 2008 at 9:09 am and is filed under Actionscript 3, Flash Components, Video. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “Video Player with XML and the FLVPlayback and DataGrid Components”

  1. Posted by sany 30th July, 2008 at 11:45 pm

    the main document class u had given is not proper , there is lotz of junk characters added on it, please update the code removing those junk chars.it start from the below for-loop

  2. Posted by admin 31st July, 2008 at 4:41 am

    for some reason i can’t get the code to render, so i posted the .as file here:

    http://manewc.com/projects/flash/VideoPlayerDataGrid/Main.as

Leave a reply