C # video Playback

Source: Internet
Author: User
Tags flv file

C # play FLV videos
Record playback video file path
private void changeflv (string path)
{
Get the path to the XML file
Xmlpath = Application.StartupPath.ToString ();
Xmlpath = xmlpath.substring (0, xmlpath.lastindexof ("\ \"));
Xmlpath = xmlpath.substring (0, xmlpath.lastindexof ("\ \"));
Xmlpath + = @ "\flvplayer";
Xmlpath + = @ "\list.xml";
XmlDocument doc = new XmlDocument ();//Create XmlDocument instance
Doc. Load (xmlpath);//Load XML file
XmlNode Nodepath = doc. selectSingleNode ("Flvlists/item");//Open node
XmlElement XE = (XmlElement) Nodepath;
Xe. SetAttribute ("title", path);//Set Element's properties
Doc. Save (Xmlpath);//Saving
}//codego.net/1/1/1/
Play FLV video Files

private void playflv (string path)//method for playing an FLV file
{
FileInfo fi2 = new FileInfo (path);//Instantiate FileInfo
if (Fi2. Exists)//If the file exists
{
Directory.CreateDirectory ("C:\\flvvidio");//Create New Folder
Randomly generated file names
String NewPath = "c:\\flvvidio\\" + DateTime.Now.Year + DateTime.Now.Second + ". flv";
File.Copy (path, NewPath);//Copy the original FLV file into the new folder
changeflv (NewPath);//Modify the playback address in the XML file
This. Text = Listview1.selecteditems[0]. Subitems[0]. text;//show the name of the file being played
Ax. Dispose ();//Release
Addflash ();//re-add player
Ax. Movie = strg;//Set movie properties
}
}
Add Playlist
private void Open File Toolstripmenuitem_click (object sender, EventArgs e)
{
if (openfiledialog1.showdialog () = = DialogResult.OK)//Select File
{
ListView1.Items.Clear ();//emptying The ListView control
string[] files = openfiledialog1.filenames;//declares an array to store the selected file
for (int i = 0; i < files. Length; i++)//traversal array
{
String flvpath = files[i];//Get path
Get file name
String flvname = Flvpath.substring (flvpath.lastindexof ("\ \") + 1, flvpath.length-flvpath.lastindexof ("\ \")-1);
fi = new FileInfo (flvpath);//instantiation of FileInfo
Flv[0] = flvname;//file name
FLV[1] = flvpath;//file path
FLV[2] = convert.tostring (FI. length/1024) + "KB";//File size
ListViewItem LVI = new ListViewItem (flv);//Create ListViewItem instance
LISTVIEW1.ITEMS.ADD (LVI);//Add to ListView control
}
}
}
Select a path to play the file after adding the list
private void Listview1_mousedoubleclick (object sender, MouseEventArgs e)
{
Try
{
if (ListView1.SelectedItems.Count > 0)//Determine if the file to be played is added
{
String path = Listview1.selecteditems[0]. SUBITEMS[1]. text;//get the path to the FLV file
playflv (path);//Call the Playflv method to play the FLV file
}
}
Catch {}
}

C # video Playback

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.