Roel Toca

Roel Toca

  • NA
  • 5
  • 2.7k

How to autoplay next song/video in WMP in C# with mysql

Oct 15 2017 8:39 AM
How do I play the next song/video from the listBox automatically
the path is inside the listBox the problem is how do I get to play the song/video in it
Here is my code:
  1. namespace JustSingSystem  
  2. {  
  3.     public partial class Karaoke : Form  
  4.     {  
  5.         MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;username=root;password=seven7");  
  6.         MySqlCommand command;  
  7.         MySqlDataReader mdr;  
  8.         public Karaoke()  
  9.         {  
  10.             InitializeComponent();  
  11.         }  
  12.   
  13.   
  14.         private void button8_Click(object sender, EventArgs e)  
  15.         {  
  16.             try  
  17.             {  
  18.                 connection.Open();  
  19.                 string selectQuery = "SELECT * FROM justsing.songsinfo WHERE songnumber=" + int.Parse(textBox1.Text);  
  20.                 command = new MySqlCommand(selectQuery, connection);  
  21.                 mdr = command.ExecuteReader();  
  22.                 if (mdr.Read())  
  23.                 {  
  24.                     textBox2.Text = mdr.GetString("song");  
  25.                     textBox3.Text = mdr.GetString("song");  
  26.   
  27.                 }  
  28.                 else  
  29.                 {  
  30.                     textBox2.Text = "";  
  31.                     textBox1.Text = "";  
  32.                     MessageBox.Show("No Data For This Id");  
  33.                 }  
  34.                 connection.Close();  
  35.                 listBox1.Items.Add(this.textBox2.Text);  
  36.                  
  37.             }  
  38.   
  39.             catch (Exception ex)  
  40.             {  
  41.                 MessageBox.Show(ex.Message);  
  42.             }  
  43.         }  
  44.   
  45.   
  46.         private void button1_Click(object sender, EventArgs e)  
  47.         {  
  48.             SoundPlayer splayer = new SoundPlayer(@"C:\Users\Tocz\Desktop\Macromedia\test.wav");  
  49.             splayer.Play();  
  50.         }  
  51.   
  52.         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)  
  53.         {  
  54.               
  55.         }  
  56.   
  57.         private void button13_Click(object sender, EventArgs e)  
  58.         {  
  59.             connection.Open();  
  60.             string selectQuery = "SELECT * FROM justsing.songsinfo WHERE songnumber=" + int.Parse(textBox1.Text);  
  61.             command = new MySqlCommand(selectQuery, connection);  
  62.             mdr = command.ExecuteReader();  
  63.             if (mdr.Read())  
  64.             {  
  65.                 textBox2.Text = mdr.GetString("song");  
  66.   
  67.             }  
  68.             else  
  69.             {  
  70.                 textBox2.Text = "";  
  71.                 textBox1.Text = "";  
  72.                 MessageBox.Show("No Data For This Id");  
  73.             }  
  74.             connection.Close();  
  75.   
  76.             axWindowsMediaPlayer1.URL = "" + textBox2.Text;  
  77.         }  
  78.   
  79.         private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)  
  80.         {  
  81.              {  
  82.         if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)  
  83.         {  
  84.             timer1.Interval = 100;  
  85.             timer1.Enabled = true;                 
  86.         }              
  87.         }    
  88.         }  
  89.       
  90.           
  91.   
  92.         private void timer1_Tick(object sender, EventArgs e)  
  93.         {  
  94.             string path = textBox2.Text;  
  95.             if (listBox1.SelectedIndex < path.Length - 1)  
  96.             {  
  97.                 listBox1.SelectedIndex++;  
  98.                 timer1.Enabled = false;  
  99.                 axWindowsMediaPlayer1.Ctlcontrols.play();  
  100.             }  
  101.             else  
  102.             {  
  103.                 listBox1.SelectedIndex = 0;  
  104.                 timer1.Enabled = false;  
  105.             }              
  106.         }  
  107.           
  108.         }  
  109.     }