//public Grid curtain;


        public MainWindow()
        {
            InitializeComponent();
            image_control        = new System.Windows.Forms.PictureBox();
            form_container.Child = image_control;
            image_control.SendToBack();
            Local.ref_addr = Directory.GetCurrentDirectory() + "\\";
            if (!Directory.Exists("danmu"))
            {
                Directory.CreateDirectory("danmu");
            }
            if (!Directory.Exists("audio"))
            {
                Directory.CreateDirectory("audio");
            }
            dmkCurt = new DanmakuCurtain();
            Console.Out.WriteLine("starting");
        }
        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();
                }
            }
        }