Design of Network TV

Source: Internet
Author: User

Recently, I stayed in the lab all day. The lab firewall was too tight and I had no entertainment at all. So I couldn't put my eyes on network TV. I thought it was shared when I downloaded it. I wanted to break it down. However, after the trial, I found that the principle was actually quite simple: the software just remembered the network TV address, then open it. ----- can such a thing be shared "?
The software only has a series of menus. clicking the menu item will open the corresponding network video, so I plan to save the menu content in the xml file and load it when the software starts, this allows you to conveniently add TV addresses. The xml file format is as follows:

<Item text = "CCTV">
<Item text = "Central" address = "mms: // 61.177.180.147/cctv1"/>
<Item text = "_" address = "mms: // winmedia.cctv.com.cn/live1"/>
</Item>

Here, text is the title displayed in the menu item, and address is the address of the network video stream. Many of them are Microsoft's mms protocol, which will be opened by media player by default.
The main content of the program is as follows. There are not many comments, but it should be easy to understand: the program only recursively reads the content in the xml file and then adds the menu item: private void Form1_Load (object sender, eventArgs e)
{
XmlDocument doc = new XmlDocument ();
// If the network is poor, a WebException may be thrown.
Doc. Load (tvListPath );
XmlElement ele = doc. DocumentElement;
XmlNodeList nodeList = ele. SelectNodes ("item"); // obtain all nodes named IIFF.
ConfigMainMenu (nodeList, this. menuStrip1, null );
}
// The address of the xml file containing the content of the menu item.
Private const string tvListPath = @ "http://uploadlist.googlepages.com/OnlineTV.xml ";
Private void commonToolStripMenuItem_Click (object sender, EventArgs e)
{
ToolStripMenuItem menuItem = sender as ToolStripMenuItem;
Debug. Assert (menuItem! = Null );
// If the Name is not set, the result is "".
If (menuItem. Name! = "")
{
Process. Start (menuItem. Name );
}
}
/** // <Summary>
/// Recursive function, adding a single dish to the main form.
/// </Summary>
/// <Param name = "nodeList"> </param>
/// <Param name = "menuStrip"> </param>
/// <Param name = "menuItem"> </param>
Public void ConfigMainMenu (XmlNodeList nodeList, MenuStrip menuStrip, ToolStripMenuItem menuItem)
{
Foreach (XmlNode node in nodeList)
{
If (node. Name = "item ")
{
XmlAttributeCollection attribute = node. Attributes;
XmlAttribute text = attribute ["text"];
If (text! = Null)
{
XmlAttribute address = attribute ["address"];
// Create a menu item based on the content of the xml file.
ToolStripMenuItem subItem = new ToolStripMenuItem (text. Value );
If (address! = Null)
{
SubItem. Name = address. Value;
}
SubItem. Click + = new EventHandler (commonToolStripMenuItem_Click );
AddItem (menuStrip, menuItem, subItem );
ConfigMainMenu (node. ChildNodes, null, subItem );
}
} // If the indicator is a separator:
Else if (node. Name = "separator ")
{
ToolStripSeparator toolStripSeparator = new ToolStripSeparator ();
AddItem (menuStrip, menuItem, toolStripSeparator );
}
Else
{
Throw new InvalidDataException ("the node name is incorrect. Check ");
}
}
}
/** // <Summary>
/// Only one of menuStrip or menuItem can be non-null, and the other can be null.
/// </Summary>
/// <Param name = "menuStrip"> </param>
/// <Param name = "menuItem"> </param>
/// <Param name = "item"> </param>
Private void addItem (MenuStrip menuStrip, ToolStripMenuItem menuItem, ToolStripItem item)
{
If (menuItem! = Null & menuStrip = null)
{
MenuItem. DropDownItems. Add (item );
}
Else if (menuStrip! = Null & menuItem = null)
{
MenuStrip. Items. Add (item );
}
Else
{
Throw new NullReferenceException ("Both menuStrip and menuItem cannot be empty or empty! ");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.