public MediaDetectorElement() { m_frames = new ObservableCollection <VideoFrame>(); Frames = new ReadOnlyObservableCollection <VideoFrame>(m_frames); m_mediaDetector = CreateMediaDetector(); Loaded += MediaDetectorElement_Loaded; }
/// <summary> /// Survient lorsqu'une vidéo n'a pas pu être chargée. /// </summary> /// <param name="sender">La source de l'évènement.</param> /// <param name="e">Les <see cref="KProcess.Presentation.Windows.Controls.RoutedMediaFailedEventArgs"/> contenant les données de l'évènement.</param> private static void MediaElement_MediaFailed(object sender, RoutedMediaFailedEventArgs e) { var dialogFactory = IoC.Resolve <System.ComponentModel.Composition.Hosting.CompositionContainer>() .GetExportedValue <IDialogFactory>(); /*if (!File.Exists(e.FileSource)) * { * TraceManager.TraceWarning(string.Format("Le fichier vidéo {0} n'existe pas.", e.FileSource)); * dialogFactory.GetDialogView<IMessageDialog>().Show(string.Format(LocalizationManager.GetString("View_MainWindow_VideoNotFound"), e.FileSource),LocalizationManager.GetString("Common_Error")); * return; * }*/ TraceManager.TraceDebug(e.Exception, e.Exception.Message); // tenter de récupérer les infos du media MediaInfo info = null; try { info = MediaDetector.GetMediaInfo(e.FileSource); } catch (Exception) { } if (info != null) { var sb = new StringBuilder("MediaInfo :"); sb.AppendLine(e.FileSource); foreach (System.ComponentModel.PropertyDescriptor prop in System.ComponentModel.TypeDescriptor.GetProperties(info.GetType())) { sb.AppendFormat("{0} = {1}{2}", prop.Name, prop.GetValue(info), Environment.NewLine); } TraceManager.TraceDebug(sb.ToString()); } /*dialogFactory.GetDialogView<IErrorDialog>() * .Show(LocalizationManager.GetString("View_MainWindow_MediaFailed"), * LocalizationManager.GetString("Common_Error"), e.Exception);*/ }
private static MediaDetector CreateMediaDetector() { MediaDetector detector = null; /* The reset event will block our thread while * we create an intialize the player */ var reset = new ManualResetEvent(false); /* We need to create a new thread for our Dispatcher */ var t = new Thread((ThreadStart) delegate { detector = new MediaDetector(); /* We queue up a method to execute * when the Dispatcher is ran. * This will wake up the calling thread * that has been blocked by the reset event */ detector.Dispatcher.Invoke((Action)(() => reset.Set())); Dispatcher.Run(); }) { Name = "MediaDetector", IsBackground = true }; t.SetApartmentState(ApartmentState.STA); /* Starts the thread and creates the object */ t.Start(); /* We wait until our object is created and * the new Dispatcher is running */ reset.WaitOne(); return(detector); }