Esempio n. 1
0
        private void play_btn_Click(object sender, EventArgs e)
        {
            //Khi chua co nhac vao
            if (listBox1.SelectedIndex == -1 && shuffle_mode_status == false && listBox1.Items.Count != 0)
            {
                listBox1.SelectedIndex = 0;
                play_now = 0;
            }
            if (listBox1.SelectedIndex == -1 && shuffle_mode_status == true && listBox1.Items.Count != 0)
            {
                listBox1.SelectedIndex = shuffle[0];
                play_now = shuffle[0];
            }
            if (listBox1.SelectedIndex != -1 && command == false && save == false && music_mode == true)
            {
                //Chay Hien thi thong tin nhac
                showtime.Enabled = true;
                //

                //Bat dau chay nhac
                sound.Source           = new Uri(path[listBox1.SelectedIndex]);
                sound.UnloadedBehavior = 0;
                sound.LoadedBehavior   = 0;
                sound.Play();
                t.Enabled = true;
                //

                //Lay thong tin nhac
                var tfile = TagLib.File.Create(path[listBox1.SelectedIndex]);
                //

                //Thoi gian
                var duration = (int)tfile.Properties.Duration.TotalSeconds;
                trackBar2.Maximum = duration;
                time.Text         = Convert.ToString(duration / 60) + ":" + Convert.ToString(duration % 60);
                //

                //Image
                if (tfile.Tag.Pictures.Length != 0)
                {
                    MemoryStream         ms    = new MemoryStream(tfile.Tag.Pictures[0].Data.Data);
                    System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
                    pictureBox1.Image = image;
                }
                //

                //Performer
                Performers = tfile.Tag.Performers;
                //

                //Title
                title = tfile.Tag.Title;
                //

                //Album
                album = tfile.Tag.Album;
                //

                //Chuyen trang thai de dung lai khi can
                command = true;
                play_btn.BackgroundImage = Sisko.Properties.Resources.icons8_gradient_line_65;
                save     = true;
                play_now = listBox1.SelectedIndex;
                //
            }
            //

            //Nhac dang dung
            else if (command == true && music_mode == true)
            {
                //Chuyen ve trang thai de chay khi can
                play_btn.BackgroundImage = Sisko.Properties.Resources.icons8_play_65;
                sound.Pause();
                t.Enabled        = false;
                showtime.Enabled = false;
                songname.Text    = "Paused";
                command          = false;
                //
            }

            //Nhac tiep tuc chay
            else if (save == true && music_mode == true)
            {   //Chuyen ve trang thai de dung khi can
                showtime.Enabled = true;
                show             = 0;
                songname.Text    = title;
                sound.Play();
                t.Enabled = true;
                command   = true;
                play_btn.BackgroundImage = Sisko.Properties.Resources.icons8_gradient_line_65;
                //
            }
            //
            //xu li khi dang o phim
            if (movie_mode == true && movie_playing == true)
            {
                play_btn.BackgroundImage = Sisko.Properties.Resources.icons8_play_65;
                t.Enabled = false;
                sound.Pause();
                movie_playing = false;
            }
            else if (movie_mode == true && movie_playing == false)
            {
                play_btn.BackgroundImage = Sisko.Properties.Resources.icons8_gradient_line_65;
                t.Enabled = true;
                sound.Play();
                movie_playing = true;
            }
        }