private void button2_Click(object sender, RoutedEventArgs e)
 {
     client = new ClientServer(ref mediaInfo);
     client.run();
     if (player == null)
     {
         danmuPlayer = new DanmuPlayer(ref dmkCurt, ref client, ref curtain);
         player      = new BitmapPlayer(ref image_control, ref form_container, ref client, ref window);
         audioPlayer = new WaveOutPlayer(ref client);
     }
 }
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            //title = InputBox("What is the title of the music?",fileName+": Title","N/A");
            string ser_ip = Interaction.InputBox("Input Server IP Address:", "IP Address:", "N/A");

            client = new ClientOnly(ser_ip, ref mediaInfo);
            client.run();
            if (player == null)
            {
                danmuPlayer = new DanmuPlayer(ref dmkCurt, ref client, ref curtain);
                player      = new BitmapPlayer(ref image_control, ref form_container, ref client, ref window);
                audioPlayer = new WaveOutPlayer(ref client);
            }
        }
        private void btn_play_Click(object sender, RoutedEventArgs e)
        {
            if (selector.SelectedItem != null)
            {
                if (image_control == null)
                {
                    image_control        = new System.Windows.Forms.PictureBox();
                    form_container.Child = image_control;

                    image_control.SendToBack();
                }

                if (player == null)
                {
                    player = new BitmapPlayer(ref image_control, ref form_container, ref client, ref window);
                }
                if (audioPlayer == null)
                {
                    audioPlayer = new WaveOutPlayer(ref client);
                }
                if (danmuPlayer == null)
                {
                    danmuPlayer = new DanmuPlayer(ref dmkCurt, ref client, ref curtain);
                }

                bool hasAudio = true;

                bool not_same = (mediaInfo.currentPlay == null) || (mediaInfo.currentPlay.fileName != selector.SelectedItem.ToString());

                if (not_same && waitToFinish != null && waitToFinish.IsAlive)
                {
                    stop();
                }
                //if not playing, or choose another file.
                if (!isPlaying || not_same)
                {
                    //change currentplay only when play it.
                    mediaInfo.select_play(selector.SelectedItem.ToString());
                    String filename = selector.SelectedItem.ToString();
                    String filepath = mediaInfo.name_to_list[filename].path;

                    waitToFinish = new Thread(wait_to_finish);

                    player.setLocalInfo(filepath, "wmv");
                    if (BitmapPlayer.header == null || BitmapPlayer.header.Count == 0)
                    {
                        return;
                    }
                    if (BitmapPlayer.isLocal == false)
                    {
                        client.askAudio(filename + ".wav");
                    }
                    if (Local.exist(@"audio\" + filename + ".wav"))
                    {
                        try
                        {
                            audioPlayer.setLocalInfo(@"audio\" + filename + ".wav");
                        }

                        catch
                        {
                            Console.Out.WriteLine("Fail to load audio");
                            hasAudio = false;
                        }
                    }
                    player.play();
                    isPlaying = true;
                    if (hasAudio)
                    {
                        audioPlayer.play();
                    }
                    danmuPlayer.playDanmu();

                    waitToFinish.Start();
                }

                if (player.isPaused == 1)
                {
                    player.play();
                    if (hasAudio)
                    {
                        audioPlayer.isPaused = 0;
                    }
                    danmuPlayer.playDanmu();
                }
            }
        }