d2Labs News and Events

Dynamic Playlist for Dynamic Multiple FLV Player

I recently needed to play multiple videos automatically and continuous with no user interaction. I ran across the Dynamic Multiple FLV Player produced by FlashDen user nosrevlah08 which seemed to closely match my requirements. After receiving the flash player I wanted to dynamically create the video play list for it to use on every page visit. It was decided to change the flash player to look at a web page for the xml content instead of the static xml file supplied with the player. 

I created an aspx page and in the Page_Load cleared the Response object and changed its content type to xml. Then created a stream reader to write xml out to the Response's OutputStream. Next, a class was created to build the xml document to fit the scheme the player needed to run and give it a list of video objects that it uses to create the dynamic xml nodes for the videos to play. I also neatly wrapped all the needed video attributes into a single class so I could pass arrays of these video objects without needing to think about what was inside of them. I have pasted code snippets below for visual reference.

I have since decided to get the video objects from a sql database which uses a random sql select statement to retrieve video records and pass the array of objects to the xml builder class. Now, every time you visit the settings aspx page, the content nodes are in random order with random records.

The flv video player can be found on http://www.flashden.net and I had excellent support from the author on tweaks to the player.

FlvPlayerSettings.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
   FlvVideo[] flvVideos = new FlvVideo[]
                    {
                        new FlvVideo("VideoOne", "VideoOne", "/Media/VideoOne.flv",427,280),
                        new FlvVideo("VideoTwo", "VideoTwo", "/Media/VideoTwo.flv",427,280),
                        new FlvVideo("VideoThree", "VideoThree", "/Media/VideoThree.flv",427,280),
                        new FlvVideo("VideoFour", "VideoFour", "/Media/VideoFour.flv",427,280)
                    };

    Response.Clear();
    Response.ContentType = "text/xml";

     using (StreamWriter sw = new StreamWriter(Response.OutputStream, Encoding.UTF8))
            {
                FlvXmlSettingsBuilder flvBuilder = new FlvXmlSettingsBuilder();

                XmlDocument doc = flvBuilder.BuildFlvSettingsDocument(flvVideos);

                sw.Write(doc.OuterXml);
                sw.Flush();
            }
            Response.End();
}

FlvXmlSettingsBuilder.cs

public XmlDocument BuildFlvSettingsDocument(FlvVideo[] videosToPlay)
{
            XmlDocument xmlDoc = new XmlDocument();
            XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", null, null);
            xmlDoc.AppendChild(dec);

            XmlElement rootNode = xmlDoc.CreateElement("flvPlayer");
            xmlDoc.AppendChild(rootNode);

            //create variables
            XmlElement variablesNode = xmlDoc.CreateElement("variables");

            variablesNode.AppendChild(BuildMeElement(xmlDoc, "videoBorderOutline", "4"));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "videoBorderColor", "0x000000"));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "mainBackgroundColor1", ""));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "mainBackgroundColor2", ""));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "controlPanelColor1", "0x000000"));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "controlPanelColor2", "0x000000"));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "textColor", "0xFFFFFF"));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "controlsGraphicsColor", "0x3399CC"));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "buttonBackgroundColor", "0x252525"));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "panelColor", "0x252525"));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "playlistPanelBackgroundColor", "0x252525"));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "hideInfo", "false"));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "hideControls", "true"));
            variablesNode.AppendChild(BuildMeElement(xmlDoc, "hidePlaylist", "true"));

            rootNode.AppendChild(variablesNode);

            foreach (FlvVideo video in videosToPlay)
            {
                XmlElement videoNode = xmlDoc.CreateElement("content");
                videoNode.AppendChild(BuildMeElement(xmlDoc, "title", video.Title));
                videoNode.AppendChild(BuildMeElement(xmlDoc, "description", video.Description));
                videoNode.AppendChild(BuildMeElement(xmlDoc, "video", video.VideoLocation));
                videoNode.AppendChild(BuildMeElement(xmlDoc, "width", video.VideoWidth.ToString()));
                videoNode.AppendChild(BuildMeElement(xmlDoc, "height", video.VideoHeight.ToString()));
                rootNode.AppendChild(videoNode);
            }
            return xmlDoc;
        }
       
        private XmlElement BuildMeElement(XmlDocument doc, string name, string value)
        {
            XmlElement newElement = doc.CreateElement(name);
            if (!string.IsNullOrEmpty(value))
            {
                newElement.InnerText = value;
            }
            return newElement;
}

FlvVideo.cs

public class FlvVideo
    {
        public string Title;
        public string Description;
        public string VideoLocation;
        public int VideoWidth;
        public int VideoHeight;

        public FlvVideo()
        {
            Title = Description = VideoLocation = "";
            VideoHeight = VideoWidth = 0;
        }

        public FlvVideo(string title, string description, string videoLocation, int videoWidth, int videoHeight)
        {
            Title = title;
            Description = description;
            VideoLocation = videoLocation;
            VideoWidth = videoWidth;
            VideoHeight = videoHeight;
        }
    }



November 1st, 2008: d2Labs is born out of the need for reasonably priced digital multimedia wor ... more

January 3rd, 2009: With the need for better quality we join two more people with backgrounds in moti ... more

January 23rd, 2009: Work is started on building our own content managment system that is easy t ... more

Dynamic Playlist for Dynamic Multiple FLV Player I recently needed to play multiple videos automatic ... more