CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Feb 2013
    Posts
    15

    How to check end of playlist of VLC or Windows Media Player ih C#

    I play mp3 with VLC and Windows Media Player playlist . But I cannot check when the playlist end. This is my code.


    First I check status field in DB, if have any row status = false Then read row from DB .


    Code:
    public void check()
            {
             MySqlConnection conn = null;
             DateTime time = DateTime.Now;
             string date_started = String.Format("{0:yyyy-MM-dd}", time);
             string time_started = String.Format("{0:HH:mm:ss}", time);
            
             try
             {
                    conn = new MySqlConnection(ConnectionString);
                    conn.Open();
    
                    MySqlDataAdapter da = new MySqlDataAdapter();
                    string sql = "SELECT * FROM queue_data WHERE status = 0 ORDER BY last_time ASC LIMIT 0,3 ";
                    da.SelectCommand = new MySqlCommand(sql, conn);
                    da.SelectCommand.ExecuteNonQuery();
                    DataSet dt = new DataSet();
                    da.Fill(dt);
    
                    if (dt.Tables[0].Rows.Count > 0)
                    {
                     num = dt.Tables[0].Rows[0].Field<int>(1);
                     ch = dt.Tables[0].Rows[0].Field<int>(2);
                     ReadTH(num, ch);                                        //  Play mp3 here.
    
                    }
             }
             catch (MySqlException ex)
             {
                    Console.WriteLine("Error: {0}", ex.ToString());
             }
             finally
             {
                    if (conn != null)
                    {
                     conn.Close();
                    }
             }
            }
    I Add mp3 to playlist like this

    Code:
     public void ReadTH(int num, int ch)
            {
             List<string> list = new List<string>();
             NumberToWords n2w = new NumberToWords();
             string call;
    
             //wplayerList2.clear();
    
             call += n2w.NumberToWordTH(num.ToString());
             call += "at";
             call += n2w.NumberToWordTH(ch.ToString());
             call += "end";
    
             list = cleanedString.Split(' ').ToList();
    
             foreach (string i in list)
             {
                    Console.WriteLine(i);
                    //wplayerList2.appendItem(axWindowsMediaPlayer2.newMedia("voicesTH\\" + i + ".mp3"));
                    axVLCPlugin21.playlist.add("file:///voicesTH/" + i + ".mp3");
    
             }
    
             axVLCPlugin21.playlist.play();
             //axWindowsMediaPlayer2.currentPlaylist = wplayerList2;
             //axWindowsMediaPlayer2.Ctlcontrols.play();
            }
    I use time check DB every 1 secound.

    Code:
     private void timer1_Tick(object sender, EventArgs e)
            {
             check();
            }
    In VLC I try to check end of playlist like this


    Code:
     private void axVLCPlugin21_MediaPlayerEndReached(object sender, EventArgs e)
            {
    
             Console.Write("OK");
             update(); //  If playlist end then update status in DB to true
    }
    In Windows Media Player I try to check end of playlist like this

    Code:
      private void axWindowsMediaPlayer2_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
            {
             if (e.newState == 8)
             {
             Console.Write("OK");
             update();   //  If playlist end then update status in DB to true
             }
            }
    When I run this code playlist can play only first mp3 file and quickly update all status field in DB to true. How to update DB after playlist end ?
    Last edited by mmc01; December 27th, 2014 at 12:48 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured