コード例 #1
0
        private void BrowseManifest_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                string fileName      = _BrowseManifestOpenFileDialog.FileName;
                string directoryName = Path.GetDirectoryName(fileName);
                string smilFilename  = Path.Combine(directoryName, Path.GetFileNameWithoutExtension(fileName) + ".ism");
                _ManifestInfo = ManifestParser.Parse(fileName);
                _SmilDocument = SmilDocument.Load(smilFilename);

                StreamInfo videoStream = _ManifestInfo.Streams.Find(stream => stream.MediaType == MediaType.Video);
                foreach (QualityLevelInfo qualityLevel in videoStream.QualityLevels)
                {
                    SmilVideo smilVideo = _SmilDocument.Body.Switch.Video.First(stream => stream.SystemBitrate == qualityLevel.Bitrate.ToString());
                    qualityLevel.TrackId  = Convert.ToInt32(smilVideo.Param.First(p => p.Name == "trackID").Value, CultureInfo.InvariantCulture);
                    qualityLevel.Filename = Path.Combine(directoryName, smilVideo.Src);
                    if (!File.Exists(qualityLevel.Filename))
                    {
                        throw new FileNotFoundException("Video file not found", qualityLevel.Filename);
                    }
                }

                StreamInfo audioStream = _ManifestInfo.Streams.Find(stream => stream.MediaType == MediaType.Audio);
                foreach (QualityLevelInfo qualityLevel in audioStream.QualityLevels)
                {
                    SmilAudio smilAudio = _SmilDocument.Body.Switch.Audio.First(stream => stream.SystemBitrate == qualityLevel.Bitrate.ToString());
                    qualityLevel.TrackId  = Convert.ToInt32(smilAudio.Param.First(p => p.Name == "trackID").Value, CultureInfo.InvariantCulture);
                    qualityLevel.Filename = Path.Combine(directoryName, smilAudio.Src);
                    if (!File.Exists(qualityLevel.Filename))
                    {
                        throw new FileNotFoundException("Video file not found", qualityLevel.Filename);
                    }
                }

                Dispatcher.Invoke(new Action(() =>
                {
                    textBoxManifestPath.Text    = fileName;
                    textBoxManifestPath.ToolTip = fileName;
                    var grid = new GridView();
                    var c1   = new GridViewColumn
                    {
                        DisplayMemberBinding = new Binding("Type"),
                        Header = "Type",
                    };
                    grid.Columns.Add(c1);
                    var c2 = new GridViewColumn
                    {
                        DisplayMemberBinding = new Binding("File"),
                        Header = "File",
                    };
                    grid.Columns.Add(c2);
                    var c3 = new GridViewColumn
                    {
                        DisplayMemberBinding = new Binding("Path"),
                        Header = "Path",
                    };
                    grid.Columns.Add(c3);
                    var coll = new ObservableCollection <object>
                    {
                        new
                        {
                            Type = "SMIL",
                            File = Path.GetFileName(smilFilename),
                            Path = smilFilename,
                        },
                        new
                        {
                            Type = "Manifest",
                            File = Path.GetFileName(fileName),
                            Path = fileName,
                        },
                    };
                    foreach (QualityLevelInfo qualityLevel in videoStream.QualityLevels)
                    {
                        coll.Add(new
                        {
                            Type = "Quality level",
                            File = Path.GetFileNameWithoutExtension(qualityLevel.Filename),
                            Path = qualityLevel.Filename,
                        });
                    }
                    listViewFiles.ItemsSource = coll;
                    listViewFiles.View        = grid;
                }));
            }
            catch (Exception ex)
            {
                _DoWorkException = ex;
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonBrowseManifest_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();

                openFileDialog.Filter      = "Manifest Files (*.ismc)|*.ismc|All Files (*.*)|*.*";
                openFileDialog.FilterIndex = 1;

                if (openFileDialog.ShowDialog() == true)
                {
                    BackgroundWorker backgroundWorker = new BackgroundWorker();

                    Exception exceptionError = null;

                    backgroundWorker.DoWork += delegate(object s, DoWorkEventArgs args)
                    {
                        try
                        {
                            string fileName = openFileDialog.FileName;

                            string directoryName = new FileInfo(fileName).Directory.FullName;

                            string smilFilename = Path.Combine(directoryName, Path.GetFileNameWithoutExtension(fileName) + ".ism");

                            manifestInfo = new ManifestParser().Parse(fileName);

                            smilDocument = SmilDocument.Load(smilFilename);

                            foreach (QualityLevelInfo qualityLevel in manifestInfo.Streams.Find(stream => stream.MediaType == MediaType.Video).QualityLevels)
                            {
                                SmilVideo smilVideo = smilDocument.Body.Switch.Video.First(stream => stream.SystemBitrate == qualityLevel.Bitrate.ToString());

                                qualityLevel.TrackId  = Convert.ToInt32(smilVideo.Param.First(p => p.Name == "trackID").Value, CultureInfo.InvariantCulture);
                                qualityLevel.Filename = Path.Combine(directoryName, smilVideo.Src);

                                if (!File.Exists(qualityLevel.Filename))
                                {
                                    throw new FileNotFoundException("Video file not found", qualityLevel.Filename);
                                }
                            }

                            foreach (QualityLevelInfo qualityLevel in manifestInfo.Streams.Find(stream => stream.MediaType == MediaType.Audio).QualityLevels)
                            {
                                SmilAudio smilAudio = smilDocument.Body.Switch.Audio.First(stream => stream.SystemBitrate == qualityLevel.Bitrate.ToString());

                                qualityLevel.TrackId  = Convert.ToInt32(smilAudio.Param.First(p => p.Name == "trackID").Value, CultureInfo.InvariantCulture);
                                qualityLevel.Filename = Path.Combine(directoryName, smilAudio.Src);

                                if (!File.Exists(qualityLevel.Filename))
                                {
                                    throw new FileNotFoundException("Video file not found", qualityLevel.Filename);
                                }
                            }

                            Dispatcher.Invoke(new Action(delegate
                            {
                                textBoxManifestPath.Text    = fileName;
                                textBoxManifestPath.ToolTip = fileName;

                                GridView grid = new GridView();

                                GridViewColumn c1       = new GridViewColumn();
                                c1.DisplayMemberBinding = new Binding("Type");
                                c1.Header = "Type";
                                grid.Columns.Add(c1);

                                GridViewColumn c2       = new GridViewColumn();
                                c2.DisplayMemberBinding = new Binding("File");
                                c2.Header = "File";
                                grid.Columns.Add(c2);

                                GridViewColumn c3       = new GridViewColumn();
                                c3.DisplayMemberBinding = new Binding("Path");
                                c3.Header = "Path";
                                grid.Columns.Add(c3);

                                ObservableCollection <object> coll = new ObservableCollection <object>();

                                coll.Add(new { Type = "SMIL", File = Path.GetFileName(smilFilename), Path = smilFilename });
                                coll.Add(new { Type = "Manifest", File = Path.GetFileName(fileName), Path = fileName });

                                foreach (QualityLevelInfo qualityLevel in manifestInfo.Streams.Find(stream => stream.MediaType == MediaType.Video).QualityLevels)
                                {
                                    coll.Add(new { Type = "Quality level", File = Path.GetFileNameWithoutExtension(qualityLevel.Filename), Path = qualityLevel.Filename });
                                }

                                listViewFiles.ItemsSource = coll;
                                listViewFiles.View        = grid;
                            }));
                        }
                        catch (Exception ex)
                        {
                            exceptionError = ex;
                        }
                    };

                    ProgressWindow progressWindow = new ProgressWindow();

                    progressWindow.Owner  = this;
                    progressWindow.Worker = backgroundWorker;

                    progressWindow.ShowDialog();

                    if (exceptionError == null)
                    {
                        labelStatus.Content       = "OK";
                        labelStatus.Background    = Brushes.LightGreen;
                        buttonCalculate.IsEnabled = true;
                    }
                    else
                    {
                        labelStatus.Content       = "Error";
                        labelStatus.Background    = Brushes.Red;
                        buttonCalculate.IsEnabled = false;

                        throw exceptionError;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorWindow errorWin = new ErrorWindow("Error reading the video set of files.", ex);
                errorWin.Owner = this;
                errorWin.ShowDialog();
            }
        }