/// <summary> /// Read Mfra box. /// </summary> /// <param name="stream">Mp4 stream.</param> /// <returns>Mfra box.</returns> private Mp4MfraBox GetMfra(Mp4Stream stream) { stream.Position = stream.Length - 4; uint mfraSize = stream.ReadUInt32(); stream.Position = stream.Length - mfraSize; var file = new Mp4File(stream); return((Mp4MfraBox)file.Boxes[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); } }
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; } }
/// <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); } }