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