Пример #1
0
        private void button4_Click(object sender, EventArgs e)
        {//10 favorite songs
            listofTracks = new List <Tracks>();
            listBox1.Items.Clear();
            SongsNPaths.Clear();
            TracksDict.Clear();
            foreach (var file in Directory.EnumerateFiles("Tracks"))
            {
                string songname = file.TrimStart("Tracks".ToCharArray());
                songname = songname.TrimEnd(".txt".ToCharArray());
                Tracks track = Tracks.DeserializeTrack(songname);
                listofTracks.Add(track);
            }
            //deinoume stin sort ton tropo me bash ton opoio tha ginei i taxinomisi diladi metaxu twn frequency ton obj
            listofTracks.Sort((track1, track2) => track1.playingFrequency.CompareTo(track2.playingFrequency));
            listofTracks.Reverse();

            for (int i = 0; i < 10; i++)
            {
                //parname ta aparaitita stoixeia sta dictionaries gia na boroun na paixoun ta tragoudia
                if (i < listofTracks.Count)
                {
                    SongsNPaths.Add(listofTracks[i].songName, listofTracks[i].path);
                    TracksDict.Add(listofTracks[i].songName, listofTracks[i]);
                    listBox1.Items.Add(listofTracks[i].songName);
                }
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string[] filenames, filepaths;
            openFileDialog1.Filter = "All Media Files|*.wav;*.aac;*.wma;*.wmv;*.avi;*.mpg;*.mpeg;*.m1v;*.mp2;*.mp3;*.mpa;*.mpe;*.m3u;*.mp4;*.mov;*.3g2;*.3gp2;*.3gp;*.3gpp;*.m4a;*.cda;*.aif;*.aifc;*.aiff;*.mid;*.midi;*.rmi;*.mkv;*.WAV;*.AAC;*.WMA;*.WMV;*.AVI;*.MPG;*.MPEG;*.M1V;*.MP2;*.MP3;*.MPA;*.MPE;*.M3U;*.MP4;*.MOV;*.3G2;*.3GP2;*.3GP;*.3GPP;*.M4A;*.CDA;*.AIF;*.AIFC;*.AIFF;*.MID;*.MIDI;*.RMI;*.MKV";
            //set default path for OFD

            if (Directory.Exists("Songs"))
            {
                openFileDialog1.InitialDirectory = "Songs";
            }

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                filenames = openFileDialog1.SafeFileNames;
                filepaths = openFileDialog1.FileNames;
                for (int i = 0; i < filenames.Length; i++)
                {
                    //elegxos wste na min uparxoun idia image files sto checkedlistbox
                    if (!SongsNPaths.ContainsKey(filenames[i]))
                    {//pairname ta names sto listbox kai names&paths sto dictionary songsnpaths
                        listBox1.Items.Add(filenames[i]);
                        SongsNPaths.Add(filenames[i], filepaths[i]);
                        //gia kathe audio file dimiourgw ena tracks obj diabazw ta metadata tou kai to apothikeuw se ena dictionary me key to onoma tou audio file
                        Tracks track = new Tracks();
                        track.path     = filepaths[i];
                        track.songName = filenames[i];
                        track.readMetaData(filepaths[i]);
                        TracksDict.Add(filenames[i], track);
                        track.playingFrequency++;

                        //gia to frequency pou akouei o xrhsths ena tragoudi
                        //to obj ginetai serialize mono tin prwti fora
                        //tis alles fores aplws auxanetai to frequency
                        if (!File.Exists(@"Tracks\" + track.songName + ".txt"))
                        {
                            Tracks.serializeTrack(track);
                        }
                        else
                        {
                            Tracks tr = Tracks.DeserializeTrack(track.songName);

                            tr.playingFrequency++;
                            Tracks.serializeTrack(tr);
                        }
                    }
                }
            }
        }