示例#1
0
        private void MainFormLoader()
        {
            if (!Application.Current.Dispatcher.CheckAccess())
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new MainFormLoaderDelegate(MainFormLoader));
            else
            {
                try
                {
                    // If we have ANY file open, close it and shut down DirectShow
                    if (this.currentState != PlayState.Init)
                        CloseClip();

                    if (isInfoLoading)
                    {
                        string info = "";
                        double maximum = 0;
                        double titleduration = 0.0;
                        int index_of_maximum = 0;
                        int num = 0;

                        //забиваем длительность
                        foreach (object obj in dvd)
                        {
                            string[] titles = (string[])obj;
                            string ifopath = Calculate.GetIFO(titles[0]);

                            if (File.Exists(ifopath))
                            {
                                //получаем информацию из ифо
                                VStripWrapper vs = new VStripWrapper();
                                vs.Open(ifopath);
                                titleduration = vs.Duration().TotalSeconds;
                                info = vs.GetVideoInfo();
                                vs.Close();

                                string titlenum = Calculate.GetTitleNum(titles[0]);
                                combo_titles.Items.Add("T" + titlenum + " " + info + " " + Calculate.GetTimeline(titleduration) + " - " + titles.Length + " file(s)");
                            }
                            else
                            {
                                //метод если нет IFO (через DS)
                                info = "";
                                bool first = true, error = false;
                                foreach (string tilte in titles)
                                {
                                    try
                                    {
                                        int hr = 0;
                                        this.graphBuilder = (IGraphBuilder)new FilterGraph();

                                        // Have the graph builder construct its the appropriate graph automatically
                                        hr = this.graphBuilder.RenderFile(tilte, null);
                                        DsError.ThrowExceptionForHR(hr);

                                        //определяем различные параметры
                                        if (first)
                                        {
                                            int resw, resh;
                                            double AvgTimePerFrame;
                                            this.basicVideo = this.graphBuilder as IBasicVideo;
                                            hr = basicVideo.get_SourceWidth(out resw);
                                            DsError.ThrowExceptionForHR(hr);
                                            hr = basicVideo.get_SourceHeight(out resh);
                                            DsError.ThrowExceptionForHR(hr);
                                            hr = basicVideo.get_AvgTimePerFrame(out AvgTimePerFrame);
                                            DsError.ThrowExceptionForHR(hr);
                                            double framerate = 1 / AvgTimePerFrame;
                                            string system = (framerate == 25.0 || framerate == 50.0) ? "PAL" : "NTSC";

                                            info = resw + "x" + resh + " " + system;
                                            first = false;
                                        }

                                        //определяем длительность
                                        double cduration = 0.0;
                                        this.mediaPosition = (IMediaPosition)this.graphBuilder;
                                        hr = mediaPosition.get_Duration(out cduration);
                                        DsError.ThrowExceptionForHR(hr);

                                        titleduration += cduration;
                                    }
                                    catch (Exception)
                                    {
                                        error = true;
                                    }
                                    finally
                                    {
                                        //освобождаем ресурсы
                                        CloseInterfaces();
                                    }
                                }

                                string titlenum = Calculate.GetTitleNum(titles[0]);
                                combo_titles.Items.Add("T" + titlenum + " " + info + " " + Calculate.GetTimeline(titleduration) + (error ? " ERROR" : "") + " - " + titles.Length + " file(s)");
                            }

                            //Ищем самый продолжительный титл
                            if (titleduration > maximum)
                            {
                                maximum = titleduration;
                                index_of_maximum = num;
                            }
                            num += 1;
                        }

                        combo_titles.Items.RemoveAt(0);
                        combo_titles.SelectedIndex = index_of_maximum;
                        this.isInfoLoading = false;
                    }

                    string[] deftitles = (string[])dvd[combo_titles.SelectedIndex];

                    if (combo_vob.Tag == null)
                    {
                        //Загружаем титл, выбираем первый воб
                        combo_vob.Items.Clear();
                        foreach (string vob in deftitles)
                            combo_vob.Items.Add(Path.GetFileName(vob).ToUpper());
                        combo_vob.SelectedIndex = 0;

                        this.filepath = deftitles[0];
                        string title_s = Calculate.GetTitleNum(this.filepath);
                        textbox_name.Text = Calculate.GetDVDName(this.filepath) + " T" + title_s;
                        m.infilepath = this.filepath;
                        m.infileslist = deftitles;
                    }
                    else
                    {
                        //Выбираем конкретный воб (только для показа в этом окне)
                        this.filepath = deftitles[(int)combo_vob.Tag];
                        combo_vob.Tag = null;

                        //При ошибке могло сброситься
                        string title_s = Calculate.GetTitleNum(this.filepath);
                        textbox_name.Text = Calculate.GetDVDName(this.filepath) + " T" + title_s;
                    }

                    //Определяем аспект для плейера (чтоб не вызывать еще раз MediaInfo)
                    string aspect = Calculate.GetRegexValue(@"\s(\d+:\d+)\s", combo_titles.SelectedItem.ToString());
                    if (!string.IsNullOrEmpty(aspect))
                    {
                        if (aspect == "4:3") in_ar = 4.0 / 3.0;
                        else if (aspect == "16:9") in_ar = 16.0 / 9.0;
                        else if (aspect == "2.2:1") in_ar = 2.21;
                    }

                    // Reset status variables
                    this.IsAudioOnly = true;
                    this.currentState = PlayState.Stopped;

                    // Start playing the media file
                    if (Settings.PlayerEngine != Settings.PlayerEngines.MediaBridge)
                        PlayMovieInWindow(this.filepath);
                    else
                        PlayWithMediaBridge(this.filepath);

                    this.Focus();
                }
                catch (Exception ex)
                {
                    CloseClip();
                    this.filepath = String.Empty;
                    textbox_name.Text = Languages.Translate("Error") + "...";
                    ErrorException(((isInfoLoading) ? "SortingTitles: " : "PlaySelectedVOB: ") + ex.Message, ex.StackTrace);
                }
            }
        }