Example #1
0
        public void setLocalInfo(String addr)
        {
            address = addr;
            if (Local.exist(address))
            {
                isLocal = true;
                reader.loadFile(Local.ref_addr + address);
            }
            else
            {
                isLocal = false;
            }
            //重新开始
            countWaveOut  = 0;
            countWaveOutP = 0;
            start         = 0;
            stream        = new List <WaveOutStream>();

            if (isLocal)
            {
                //本地
                load_waveoutstream = new Thread(loadWaveOutStream);
                load_waveoutstream.Start();

                Client.audio = 1;
                while (stream.Count < 1)
                {
                }
                start = 1;
            }
            else
            {
                //别人的

                client.askAudio(address);
                reader.loadFile(Local.ref_addr + address);
                isLocal = true;
                setLocalInfo(addr);
            }
        }
        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();
                }
            }
        }