Exemplo n.º 1
0
        private void Open(object obj)
        {
            try
            {
                var openFileDialog = new OpenFileDialog
                {
                    Filter      = "MP4 Files (*.mp4,*.m4a,*.ismv,*.mov)|*.mp4;*.m4a;*.ismv;*.mov|All Files (*.*)|*.*",
                    FilterIndex = 1
                };

                if (openFileDialog.ShowDialog() == true)
                {
                    _Stream?.Close();
                    var       backgroundWorker = new BackgroundWorker();
                    Exception exceptionError   = null;
                    backgroundWorker.DoWork += (object s, DoWorkEventArgs args) =>
                    {
                        try
                        {
                            _Stream = new Mp4Stream(openFileDialog.OpenFile());
                            _File   = new Mp4File(_Stream);
                            List <Mp4Box> unknowBoxes = _File.Boxes.FindAll(b => b is Mp4UnknownBox);
                            if (unknowBoxes.Count > 1)
                            {
                                throw new Exception("Too many unknown boxes.");
                            }
                            View.Dispatcher.Invoke(new Action(() =>
                            {
                                View.RootNode = BuildTree(_File, Path.GetFileName(openFileDialog.FileName));
                                _Controller.RemoveViews();
                            }));
                        }
                        catch (Exception ex)
                        {
                            exceptionError = ex;
                        }
                    };
                    var progressWindow = new ProgressWindow(backgroundWorker);
                    progressWindow.ShowDialog();
                    if (exceptionError != null)
                    {
                        throw exceptionError;
                    }
                }
            }
            catch
            {
                MessageBox.Show("Error loading mp4 file", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
        private void ReadMp4File(Stream fileStream, string fileName)
        {
            if (stream != null)
            {
                stream.Close();
            }

            BackgroundWorker backgroundWorker = new BackgroundWorker();
            Exception        exceptionError   = null;

            backgroundWorker.DoWork += delegate
            {
                try
                {
                    stream = new Mp4Stream(fileStream);
                    file   = new Mp4File(stream);

                    List <Mp4Box> unknowBoxes = file.Boxes.FindAll(b => b is Mp4UnknownBox);

                    if (unknowBoxes.Count > 1)
                    {
                        throw new Exception("Too many unknow boxes.");
                    }

                    View.Dispatcher.Invoke(new Action(delegate
                    {
                        this.View.RootNode = BuildTree(file, new FileInfo(fileName).Name);

                        controller.RemoveViews();
                    }));
                }
                catch (Exception ex)
                {
                    exceptionError = ex;
                }
            };

            ProgressWindow progressWindow = new ProgressWindow();

            progressWindow.Worker = backgroundWorker;

            progressWindow.ShowDialog();

            if (exceptionError != null)
            {
                throw exceptionError;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        private void Open(object obj)
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();

                //openFileDialog.Filter = "MP4 Files (*.mp4,*.m4a,*.ismv,*.mov,*.qlv)|*.mp4;*.m4a;*.ismv;*.mov;*.qlv|All Files (*.*)|*.*";
                openFileDialog.Filter      = "MP4 Files (*.mp4,*.m4a,*.ismv,*.mov)|*.mp4;*.m4a;*.ismv;*.mov|All Files (*.*)|*.*";
                openFileDialog.FilterIndex = 1;

                if (openFileDialog.ShowDialog() == true)
                {
                    if (stream != null)
                    {
                        stream.Close();
                    }

                    BackgroundWorker backgroundWorker = new BackgroundWorker();

                    Exception exceptionError = null;

                    backgroundWorker.DoWork += delegate(object s, DoWorkEventArgs args)
                    {
                        try
                        {
                            stream = new Mp4Stream(openFileDialog.OpenFile());
                            file   = new Mp4File(stream);

                            List <Mp4Box> unknowBoxes = file.Boxes.FindAll(b => b is Mp4UnknownBox);

                            //if (unknowBoxes.Count > 1)
                            //    throw new Exception("Too many unknow boxes.");

                            View.Dispatcher.Invoke(new Action(delegate
                            {
                                this.View.RootNode = BuildTree(file, new FileInfo(openFileDialog.FileName).Name);

                                controller.RemoveViews();
                            }));
                        }
                        catch (Exception ex)
                        {
                            exceptionError = ex;
                        }
                    };

                    ProgressWindow progressWindow = new ProgressWindow();

                    progressWindow.Worker = backgroundWorker;

                    progressWindow.ShowDialog();

                    if (exceptionError != null)
                    {
                        throw exceptionError;
                    }
                }
            }
            catch
            {
                MessageBox.Show("Error loading mp4 file", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }