C # simple Music player ListBox single List

Source: Internet
Author: User

Simple music player implementation is not difficult, directly with AxWindowsMediaPlayer to do, there is no technical content, but AxWindowsMediaPlayer is not to generate a single list of songs, that is, After each add music AxWindowsMediaPlayer is not recorded, then I would like to make a simple list of songs.

AxWindowsMediaPlayer working principle is actually based on path to load, in the writing of the song we need to do two things first, 1, save the song Path 2, save the song name here for the time being regardless of the database, I use IO operation through the TXT file to store both information.

Thought process:

Determines whether a file exists-----exists------write stream to the data------update the ListBox

-----does not exist------create two files-------write stream to the data------update the ListBox

It's not a problem. We have to use two ListBox, one to display the song name, one to save the path, and to have two listbox associated

IO Operation code:

1   Public voidIostreamname ()2         { 3             if(File.exists (namepath))4             {5                 //Deposit file Name6                //MessageBox.Show ("1 exists! ");7StreamWriter Namewriter =NewStreamWriter (Namepath,true);8                 if(ListSafeFileName.Items.Count >0)9                 {Ten                      for(inti =0; i < ListSafeFileName.Items.Count; i++) One                     { ANamewriter.writeline (Listsafefilename.items [Listsafefilename. Items. Count-1]. ToString ()); -                          Break; -                     } the namewriter.close (); -                 }  -             } -             Else +             { -                 //creating file name files +FileStream Safefilename =NewFileStream (Namepath, filemode.create); A safefilename.close (); atStreamWriter Namewriter =NewStreamWriter (namepath); -                  for(inti =0; i < ListSafeFileName.Items.Count; i++) -                 { -Namewriter.writeline (Listsafefilename.items[listsafefilename.items.count-1]. ToString ()); -                 } - namewriter.close (); in                  -             } to}
Iostreamname
1  Public voidIostreamfilename ()2         {3             if(File.exists (filenamepath))4             {5                 //Deposit File Path6                //MessageBox.Show ("2 exists! ");7StreamWriter Filenamewriter =NewStreamWriter (Filenamepath,true);8                 if(ListFileName.Items.Count >0)9                 {Ten                      for(inti =0; i < ListFileName.Items.Count; i++) One                     { AFilenamewriter.writeline (Listfilename.items[listfilename.items.count-1]. ToString ()); -                          Break; -                     } the filenamewriter.close (); -                 } -             } -             Else +             { -                 //Create a path file +FileStream FileName =NewFileStream (Filenamepath, filemode.create); A filename.close (); atStreamWriter Filenamewriter =NewStreamWriter (filenamepath); -                  for(inti =0; i < ListFileName.Items.Count; i++) -                 { -Filenamewriter.writeline (Listfilename.items[listfilename.items.count-1]. ToString ()); -                 } - filenamewriter.close (); in                 -             } to}
Iostreamfilename

ListBox Correlation Ideas

1  Private voidListsafefilename_mousedoubleclick (Objectsender, MouseEventArgs e)2         {3             if(Listsafefilename.selectedindex >=0)4             {5Listfilename.selectedindex =Listsafefilename.selectedindex;6Winplayer.url =ListFileName.SelectedItem.ToString ();7             }8}
Listsafefilename

Launch that update list (here to say, update, I wrote two functions, here the algorithm is more classic, is really the listbox to play out the flowers, code to write this is actually the most enjoyable)

1   Public voidIostreamreadname ()2         {3             if(File.exists (namepath))4             {5StreamReader Musicname =NewStreamReader (namepath);6                 string[] Txtdata =File.ReadAllLines (namepath);7                  for(inti =0; i < txtdata.length; i++)8                 {9 ListSafeFileName.Items.Add (Musicname.readline ());Ten                 } One musicname.close (); A             } -  -}
Iostreamreadname
1  Public voidIostreamreadfilename ()2         {3             if(File.exists (filenamepath))4             {5StreamReader Musicfilename =NewStreamReader (filenamepath);6                 string[] Txtdata =File.ReadAllLines (filenamepath);7                  for(inti =0; i < txtdata.length; i++)8                 {9 ListFileName.Items.Add (Musicfilename.readline ());Ten                 } One musicfilename.close (); A             } -}
Iostreamreadfilename

Posted here are the core code, in fact, then think of TXT file is not easy to manage, with a generic set is also very good, need to improve it.

C # simple Music player ListBox single List

Related Article

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.