/// <summary> /// Initializes the target bitmap. Pass a null block to initialize with the default video properties. /// </summary> /// <param name="block">The block.</param> private void InitializeTargetBitmap(VideoBlock block) { WPFUtils.UIInvoke(DispatcherPriority.Normal, () => { var visual = PresentationSource.FromVisual(MediaElement); var dpiX = 96.0 * visual?.CompositionTarget?.TransformToDevice.M11 ?? 96.0; var dpiY = 96.0 * visual?.CompositionTarget?.TransformToDevice.M22 ?? 96.0; var pixelWidth = block?.PixelWidth ?? MediaElement.NaturalVideoWidth; var pixelHeight = block?.PixelHeight ?? MediaElement.NaturalVideoHeight; if (MediaElement.HasVideo && pixelWidth > 0 && pixelHeight > 0) { TargetBitmap = new WriteableBitmap( block?.PixelWidth ?? MediaElement.NaturalVideoWidth, block?.PixelHeight ?? MediaElement.NaturalVideoHeight, dpiX, dpiY, PixelFormats.Bgr24, null); } else { TargetBitmap = null; } MediaElement.ViewBox.Source = TargetBitmap; }); }
internal void RaiseMediaFailedEvent(Exception ex) { LogEventStart(MediaFailedEvent); Logger.Log(MediaLogMessageType.Error, $"Media Failure - {ex?.GetType()}: {ex?.Message}"); WPFUtils.UIInvoke(DispatcherPriority.DataBind, () => { RaiseEvent(CreateExceptionRoutedEventArgs(MediaFailedEvent, this, ex)); }); LogEventDone(MediaFailedEvent); }
/// <summary> /// Executed when the Close method is called on the parent MediaElement /// </summary> public void Close() { WPFUtils.UIInvoke(DispatcherPriority.Render, () => { TargetBitmap = null; MediaElement.ViewBox.Source = null; }); }
internal void RaiseMediaOpeningEvent() { LogEventStart(MediaOpeningEvent); WPFUtils.UIInvoke(DispatcherPriority.DataBind, () => { RaiseEvent(new MediaOpeningRoutedEventArgs(MediaOpeningEvent, this, mediaElementCore.Container.MediaOptions, mediaElementCore.Container.MediaInfo)); }); LogEventDone(MediaOpeningEvent); }
/// <summary> /// Initializes static members of the <see cref="MediaElement"/> class. /// </summary> static MediaElement() { var style = new Style(typeof(MediaElement), null); style.Setters.Add(new Setter(FlowDirectionProperty, FlowDirection.LeftToRight)); style.Seal(); StyleProperty.OverrideMetadata(typeof(MediaElement), new FrameworkPropertyMetadata(style)); // Platform specific implementation Platform.SetDllDirectory = NativeMethods.SetDllDirectory; Platform.CopyMemory = NativeMethods.CopyMemory; Platform.FillMemory = NativeMethods.FillMemory; Platform.CreateTimer = (priority) => { return(new CustomDispatcherTimer((DispatcherPriority)priority)); }; // Setup the Platform-specific factory callbacks Platform.UIInvoke = (priority, action) => WPFUtils.UIInvoke((DispatcherPriority)priority, action); Platform.UIEnqueueInvoke = (priority, action, args) => WPFUtils.UIEnqueueInvoke((DispatcherPriority)priority, action, args); Platform.CreateRenderer = (mediaType, m) => { if (mediaType == MediaType.Audio) { return(new AudioRenderer(m)); } else if (mediaType == MediaType.Video) { return(new VideoRenderer(m)); } else if (mediaType == MediaType.Subtitle) { return(new SubtitleRenderer(m)); } throw new ArgumentException($"No suitable renderer for Media Type '{mediaType}'"); }; // Simply forward the calls MediaElementCore.FFmpegMessageLogged += (o, e) => FFmpegMessageLogged?.Invoke(o, e); }
/// <summary> /// Initializes a new instance of the <see cref="AudioRenderer"/> class. /// </summary> /// <param name="mediaElementCore">The core media element.</param> public AudioRenderer(MediaElementCore mediaElementCore) { MediaElementCore = mediaElementCore; m_Format = new WaveFormat(AudioParams.Output.SampleRate, AudioParams.OutputBitsPerSample, AudioParams.Output.ChannelCount); if (WaveFormat.BitsPerSample != 16 || WaveFormat.Channels != 2) { throw new NotSupportedException("Wave Format has to be 16-bit and 2-channel."); } if (MediaElement.HasAudio) { Initialize(); } if (Application.Current != null) { WPFUtils.UIInvoke(DispatcherPriority.Normal, () => { Application.Current.Exit += OnApplicationExit; }); } }
private void RaiseMediaEndedEvent() { LogEventStart(MediaEndedEvent); WPFUtils.UIInvoke(DispatcherPriority.DataBind, () => { RaiseEvent(new RoutedEventArgs(MediaEndedEvent, this)); }); LogEventDone(MediaEndedEvent); }