11 Ekim 2015 Pazar

C# Müzik Çalar Yapımı



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;



namespace media_player
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                String[] degerler = new String[] { };
                degerler = (File.ReadAllLines("D:\\ParcaListesi.txt"));
                for (int j = 0; j <= degerler.Length; j++)
                {
                    listBox1.Items.Add(degerler.GetValue(j));
                }
            }
            catch
            {
            }
            try
            {
                sahip1.Text = " Copyright Fikri KOCAOGLAN™";
                bilgilabel1.Text = "Listede Toplam " + listBox1.Items.Count + " Tane Parça Var.";
                listBox1.SetSelected(i, true);
            }
            catch
            { }
        }
        Random rnd = new Random();
        private void muzikcal()
        {
            try
            {
                if (listBox1.Items.Count != 0)
                {
                    if (radioButton1.Checked==true)
                    {
                        axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
                        i++;
                        listBox1.SetSelected(i, true);
                    }
                    else if (radioButton2.Checked == true)
                    {
                        axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
                        listBox1.SetSelected(rnd.Next(0, listBox1.Items.Count), true);
                    }
                }
                else
                {
                    MessageBox.Show("Önce Listeye Müzik Eklemelisiniz!", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
            }
            catch
            {

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
         
            muzikcal();
            if (checkBox1.Checked)
            {
                if (listBox1.Items.Count != 0)
                {
                    timer1.Enabled = true;
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
                folderBrowserDialog1.ShowDialog();
                string yol = folderBrowserDialog1.SelectedPath;

                listBox1.Items.Clear();
                try
                {
                    foreach (string bulunandosya in Directory.GetFiles
                        (yol, "*.mp3", SearchOption.TopDirectoryOnly))
                        listBox1.Items.Add(bulunandosya);
                    listBox1.SetSelected(i, true);
                }
                catch
                {
                try
                {
                    foreach (string bulunandosya in Directory.GetFiles
                       (yol, "*.mp4", SearchOption.TopDirectoryOnly))
                        listBox1.Items.Add(bulunandosya);
                    listBox1.SetSelected(i, true);
                }
                catch
                {
                try
                {
                    foreach (string bulunandosya in Directory.GetFiles
                       (yol, "*.wav", SearchOption.TopDirectoryOnly))
                        listBox1.Items.Add(bulunandosya);
                    listBox1.SetSelected(i, true);
                }
                catch
                {
                try
                {
                    foreach (string bulunandosya in Directory.GetFiles
                       (yol, "*.avi", SearchOption.TopDirectoryOnly))
                        listBox1.Items.Add(bulunandosya);
                    listBox1.SetSelected(i, true);
                }
                catch
                {
                    MessageBox.Show("Herhangi bir Media Dosyası Bulunamadı!!!", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                }
                }
                }
                bilgilabel1.Text = "Listede Toplam " + listBox1.Items.Count + " Tane Parça Listeye Eklendi.";
         
        }
        int i = 0;
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (listBox1.Items.Count != 0)
                {
                    if (radioButton1.Checked == true && checkBox1.Checked == false)
                    {
                        if (i > 0)
                        {
                            i--;
                            listBox1.SetSelected(i, true);
                            axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
                        }
                        else
                        {
                            i = listBox1.Items.Count - 1;
                            listBox1.SetSelected(i, true);
                            axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
                        }
                    }
                    else if (radioButton1.Checked == true && checkBox1.Checked == true)
                    {
                        if (i > 0)
                        {
                            timer1.Enabled = false;
                            i--;
                            listBox1.SetSelected(i, true);
                            axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
                            timer1.Enabled = true;
                        }
                        else
                        {
                            timer1.Enabled = false;
                            i = listBox1.Items.Count - 1;
                            listBox1.SetSelected(i, true);
                            axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
                            timer1.Enabled = true;
                        }
                    }
                    else
                    {
                        axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
                        listBox1.SetSelected(rnd.Next(0, listBox1.Items.Count), true);
                    }

                }
                else
                {
                    MessageBox.Show("Önce Listeye Müzik Eklemelisiniz!", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
            }
            catch
            {

            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                if (listBox1.Items.Count != 0)
                {
                    if (radioButton1.Checked == true && checkBox1.Checked == false)
                    {
                        if (i < listBox1.Items.Count - 1)
                        {
                            sayac++;
                            i++;
                            listBox1.SetSelected(i, true);
                            axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
                        }
                        else if (i == listBox1.Items.Count - 1)
                        {
                            i = 0;
                            listBox1.SetSelected(i, true);
                            axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
                        }
                    }
                    else if (radioButton1.Checked == true && checkBox1.Checked == true)
                    {
                        if (i < listBox1.Items.Count - 1)
                        {
                            timer1.Enabled = false;
                            i++;
                            listBox1.SetSelected(i, true);
                            axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
                            timer1.Enabled = true;
                        }
                        else if (i == listBox1.Items.Count - 1)
                        {
                            timer1.Enabled = false;
                            i = 0;
                            listBox1.SetSelected(i, true);
                            axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
                            timer1.Enabled = true;
                        }
                    }
                    else
                    {
                        axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
                        listBox1.SetSelected(rnd.Next(0, listBox1.Items.Count), true);
                    }
                    if (radioButton1.Checked)
                    {
                        if (sayac == listBox1.Items.Count - 1)
                        {
                            timer1.Enabled = false;
                            MessageBox.Show("Tüm Müzikler Çalındı!", "BİLGİ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Önce Listeye Müzik Eklemelisiniz!", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
            }
            catch
            {

            }
        }
        int sayac = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            string kalanSure = axWindowsMediaPlayer1.Ctlcontrols.currentPositionString.ToString();
            string maxSure =  axWindowsMediaPlayer1.Ctlcontrols.currentItem.durationString;
            int maxx = Convert.ToInt32(axWindowsMediaPlayer1.Ctlcontrols.currentPosition);
            int kalann = Convert.ToInt32(axWindowsMediaPlayer1.Ctlcontrols.currentItem.duration);
            if (kalann == maxx)
            {
                sayac++;
                muzikcal();
            }
            if (radioButton1.Checked)
            {
                if (sayac == listBox1.Items.Count - 1)
                {
                    timer1.Enabled = false;
                    MessageBox.Show("Tüm Müzikler Çalındı!", "BİLGİ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
         
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
                timer1.Enabled = true;
            else
                timer1.Enabled = false;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.stop();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (listBox1.Items.Count != 0)
            {
                FileStream fs = new FileStream("D:\\ParcaListesi.txt",
                    FileMode.Create, FileAccess.Write, FileShare.Write);
                StreamWriter sw = new StreamWriter(fs);
                for (int i = 0; i <= listBox1.Items.Count - 1; i++)
                    sw.WriteLine(listBox1.Items[i]);
                sw.Close();
                MessageBox.Show("Liste Kaydedildi!", "BİLGİ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                bilgilabel1.Text = "Listeye Toplam " + listBox1.Items.Count + " Tane Parça Eklendi.";

            }
            else
            {
                MessageBox.Show("Liste Boş!", "BİLGİ", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Listeyi Silmek İstiyormusunuz?", "BİLGİ", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)==DialogResult.Yes)
                {
                    File.Delete("D:\\ParcaListesi.txt");
                    MessageBox.Show("Liste Silindi!", "BİLGİ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    listBox1.Items.Clear();
                    bilgilabel1.Text = "Listede Toplam " + listBox1.Items.Count + " Tane Parça Var.";

                }
                else
                {
                    MessageBox.Show("Liste Silme İşlemi İptal Edildi!", "BİLGİ", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
            }
            catch (Exception ex)
            { }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            try
            {
                sahip1.Text = sahip1.Text.Substring(1) + sahip1.Text.Substring(0, 1);
            }
            catch
            { }
        }
    }
}


Paylaş:

0 yorum:

Yorum Gönder

Popüler

Son

Kategoriler