Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaLogMessagEventArgs" /> class.
 /// </summary>
 /// <param name="mediaElement">The media element.</param>
 /// <param name="messageType">Type of the message.</param>
 /// <param name="message">The message.</param>
 public MediaLogMessagEventArgs(MediaElementCore mediaElement, MediaLogMessageType messageType, string message)
     : base()
 {
     MessageType  = messageType;
     Message      = message;
     TimestampUtc = DateTime.UtcNow;
     Source       = mediaElement;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MediaElement" /> class.
        /// </summary>
        public MediaElement()
            : base()
        {
            ContentGrid = new Grid {
                Name = nameof(ContentGrid)
            };
            Content = ContentGrid;
            ContentGrid.HorizontalAlignment = HorizontalAlignment.Stretch;
            ContentGrid.VerticalAlignment   = VerticalAlignment.Stretch;
            ContentGrid.Children.Add(ViewBox);
            Stretch          = ViewBox.Stretch;
            StretchDirection = ViewBox.StretchDirection;
            Logger           = new GenericMediaLogger <MediaElement>(this);

            mediaElementCore = new MediaElementCore(this, WPFUtils.IsInDesignTime);

            if (WPFUtils.IsInDesignTime)
            {
                // Shows an FFmpeg image if we are in design-time
                var bitmap       = Properties.Resources.FFmpegMediaElementBackground;
                var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(
                    bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                var controlBitmap = new WriteableBitmap(bitmapSource);
                ViewBox.Source = controlBitmap;
            }
            else
            {
                // Bind to RoutedEvent events
                mediaElementCore.MediaOpening     += (s, e) => RaiseMediaOpeningEvent();
                mediaElementCore.MediaOpened      += (s, e) => RaiseMediaOpenedEvent();
                mediaElementCore.MediaClosed      += (s, e) => RaiseMediaClosedEvent();
                mediaElementCore.MediaFailed      += (s, e) => RaiseMediaFailedEvent(e.Exception);
                mediaElementCore.MediaEnded       += (s, e) => RaiseMediaEndedEvent();
                mediaElementCore.BufferingStarted += (s, e) => RaiseBufferingStartedEvent();
                mediaElementCore.BufferingEnded   += (s, e) => RaiseBufferingEndedEvent();
                mediaElementCore.SeekingStarted   += (s, e) => RaiseSeekingStartedEvent();
                mediaElementCore.SeekingEnded     += (s, e) => RaiseSeekingEndedEvent();

                // Bind to non-RoutedEvent events
                mediaElementCore.MessageLogged   += (o, e) => MessageLogged?.Invoke(this, e);
                mediaElementCore.PositionChanged += (s, e) => PositionChanged?.Invoke(this, e);

                // Bind to INotifyPropertyChanged event: PropertyChanged
                mediaElementCore.PropertyChanged += MediaElementCore_PropertyChanged;
            }

            m_Metadata = CollectionViewSource.GetDefaultView(mediaElementCore.Metadata) as ICollectionView;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PositionChangedEventArgs"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="position">The position.</param>
 public PositionChangedEventArgs(MediaElementCore source, TimeSpan position)
 {
     Position = position;
     Source   = source;
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaOpeningEventArgs" /> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="options">The options.</param>
 /// <param name="info">The information.</param>
 public MediaOpeningEventArgs(MediaElementCore source, MediaOptions options, MediaInfo info)
 {
     Source  = source;
     Options = options;
     Info    = info;
 }