Windows Dev Center

Développer Réduire

MediaElement Class

Représente un objet qui contient des données audio, vidéo ou les deux.

Pour plus d'informations sur la lecture audio et vidéo dans une application Windows Store conçue pour Windows et utilisant C++, C# ou Visual Basic, consultez Démarrage rapide : création d'une application de lecteur multimédia et Démarrage rapide : vidéo et audio.

Pour obtenir un exemple qui utilise MediaElement pour la lecture vidéo, consultez Exemple de lecture du média en XAML.

Héritage

Object
  DependencyObject
    UIElement
      FrameworkElement
        MediaElement

Syntaxe


public sealed class MediaElement : FrameworkElement

Attributs

ActivatableAttribute(NTDDI_WIN8)
MarshalingBehaviorAttribute(Agile)
StaticAttribute(Windows.UI.Xaml.Controls.IMediaElementStatics, NTDDI_WIN8)
ThreadingAttribute(Both)
VersionAttribute(NTDDI_WIN8)
WebHostHiddenAttribute()

Membres

MediaElementClasse comporte les types de membres suivants :

Constructeurs

MediaElementClasse comporte les constructeurs suivants.

ConstructeurDescription
MediaElement Instantiates a new instance of the MediaElement class.

 

Événements

MediaElementClasse comporte les événements suivants.

ÉvénementDescription
BufferingProgressChanged Occurs when the BufferingProgress property changes.
CurrentStateChanged Occurs when the value of the CurrentState property changes.
DoubleTapped Occurs when an otherwise unhandled DoubleTap interaction occurs over the hit test area of this element. (Hérité de UIElement)
DownloadProgressChanged Occurs when the DownloadProgress property has changed.
DragEnter Occurs when the input system reports an underlying drag event with this element as the target. (Hérité de UIElement)
DragLeave Occurs when the input system reports an underlying drag event with this element as the origin. (Hérité de UIElement)
DragOver Occurs when the input system reports an underlying drag event with this element as the potential drop target. (Hérité de UIElement)
Drop Occurs when the input system reports an underlying drop event with this element as the drop target. (Hérité de UIElement)
GotFocus Occurs when a UIElement receives focus. (Hérité de UIElement)
Holding Occurs when an otherwise unhandled Hold interaction occurs over the hit test area of this element. (Hérité de UIElement)
KeyDown Occurs when a keyboard key is pressed while the UIElement has focus. (Hérité de UIElement)
KeyUp Occurs when a keyboard key is released while the UIElement has focus. (Hérité de UIElement)
LayoutUpdated Occurs when the layout of the visual tree changes. (Hérité de FrameworkElement)
Loaded Occurs when a FrameworkElement has been constructed and added to the object tree, and is ready for interaction. (Hérité de FrameworkElement)
LostFocus Occurs when a UIElement loses focus. (Hérité de UIElement)
ManipulationCompleted Occurs when a manipulation on the UIElement is complete. (Hérité de UIElement)
ManipulationDelta Occurs when the input device changes position during a manipulation. (Hérité de UIElement)
ManipulationInertiaStarting Occurs when the input device loses contact with the UIElement object during a manipulation and inertia begins. (Hérité de UIElement)
ManipulationStarted Occurs when an input device begins a manipulation on the UIElement. (Hérité de UIElement)
ManipulationStarting Occurs when the manipulation processor is first created. (Hérité de UIElement)
MarkerReached Occurs when a timeline marker is encountered during media playback.
MediaEnded Occurs when the MediaElement finishes playing audio or video.
MediaFailed Occurs when there is an error associated with the media Source.
MediaOpened Occurs when the media stream has been validated and opened, and the file headers have been read.
PointerCanceled Occurs when a pointer that made contact abnormally loses contact. (Hérité de UIElement)
PointerCaptureLost Occurs when pointer capture previously held by this element moves to another element or elsewhere. (Hérité de UIElement)
PointerEntered Occurs when a pointer enters the hit test area of this element. (Hérité de UIElement)
PointerExited Occurs when a pointer leaves the hit test area of this element. (Hérité de UIElement)
PointerMoved Occurs when a pointer moves while the pointer remains within the hit test area of this element. (Hérité de UIElement)
PointerPressed Occurs when the pointer device initiates a Press action within this element. (Hérité de UIElement)
PointerReleased Occurs when the pointer device that previously initiated a Press action is released, while within this element. (Hérité de UIElement)
PointerWheelChanged Occurs when the delta value of a pointer wheel changes. (Hérité de UIElement)
RateChanged Occurs when PlaybackRate or DefaultPlaybackRate changes value.
RightTapped Occurs when a right-tap input stimulus happens while the pointer is over the element. (Hérité de UIElement)
SeekCompleted Occurs when the seek point of a requested seek operation is ready for playback.
SizeChanged Occurs when either the ActualHeight or the ActualWidth property changes value on a FrameworkElement. (Hérité de FrameworkElement)
Tapped Occurs when an otherwise unhandled Tap interaction occurs over the hit test area of this element. (Hérité de UIElement)
Unloaded Occurs when this object is no longer connected to the main object tree. (Hérité de FrameworkElement)
VolumeChanged Occurs when the value of the Volume property changes.

 

Méthodes

The MediaElement Classe comporte les méthodes suivantes. Il hérite également des méthodes de Object Classe.

MéthodeDescription
AddAudioEffect Applies an audio effect to playback. Takes effect for the next source that is set on this MediaElement.
AddHandler Adds a routed event handler for a specified routed event, adding the handler to the handler collection on the current element. Specify handledEventsToo as true to have the provided handler be invoked even if the event is handled elsewhere. (Hérité de UIElement)
AddVideoEffect Applies a video effect to playback. Takes effect for the next source that is set on this MediaElement.
Arrange Positions child objects and determines a size for a UIElement. Parent objects that implement custom layout for their child elements should call this method from their layout override implementations to form a recursive layout update. (Hérité de UIElement)
ArrangeOverride Provides the behavior for the Arrange pass of layout. Classes can override this method to define their own Arrange pass behavior. (Hérité de FrameworkElement)
CanPlayType Returns an enumeration value that describes the likelihood that the current MediaElement and its client configuration can play that media source.
CapturePointer Sets pointer capture to a UIElement. Once captured, only the element that has capture will fire pointer-related events. (Hérité de UIElement)
ClearValue Clears the local value of a dependency property. (Hérité de DependencyObject)
FindName Retrieves an object that has the specified identifier name. (Hérité de FrameworkElement)
FindSubElementsForTouchTargeting Enables a UIElement subclass to expose child elements that assist with resolving touch targeting. (Hérité de UIElement)
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Hérité de DependencyObject)
GetAudioStreamLanguage Returns the RFC 1766 language for the specified audio stream.
GetValue Returns the current effective value of a dependency property from a DependencyObject. (Hérité de DependencyObject)
InvalidateArrange Invalidates the arrange state (layout) for a UIElement. After the invalidation, the UIElement will have its layout updated, which will occur asynchronously. (Hérité de UIElement)
InvalidateMeasure Invalidates the measurement state (layout) for a UIElement. (Hérité de UIElement)
Measure Updates the DesiredSize of a UIElement. Typically, objects that implement custom layout for their layout children call this method from their own MeasureOverride implementations to form a recursive layout update. (Hérité de UIElement)
MeasureOverride Provides the behavior for the Measure pass of the layout cycle. Classes can override this method to define their own Measure pass behavior. (Hérité de FrameworkElement)
OnApplyTemplate Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class. (Hérité de FrameworkElement)
OnCreateAutomationPeer When implemented in a derived class, returns class-specific AutomationPeer implementations for the Microsoft UI Automation infrastructure. (Hérité de UIElement)
OnDisconnectVisualChildren Override this method to implement how layout and logic should behave when items are removed from a class-specific content or children property. (Hérité de UIElement)
Pause Pauses media at the current position.
Play Plays media from the current position.
ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Hérité de DependencyObject)
ReleasePointerCapture Releases pointer captures for capture of one specific pointer by this UIElement. (Hérité de UIElement)
ReleasePointerCaptures Releases all pointer captures held by this element. (Hérité de UIElement)
RemoveAllEffects Removes all effects for the next source set for this MediaElement.
RemoveHandler Removes the specified routed event handler from this UIElement. Typically the handler in question was added by AddHandler. (Hérité de UIElement)
SetBinding Attaches a binding to a FrameworkElement, using the provided binding object. (Hérité de FrameworkElement)
SetSource Sets the Source property using the supplied stream.
SetValue Sets the local value of a dependency property on a DependencyObject. (Hérité de DependencyObject)
Stop Stops and resets media to be played from the beginning.
TransformToVisual Returns a transform object that can be used to transform coordinates from the UIElement to the specified object. (Hérité de UIElement)
UpdateLayout Ensures that all positions of child objects of a UIElement are properly updated for layout. (Hérité de UIElement)

 

Propriétés

Le MediaElementClasse contient les propriétés suivantes.

PropriétéType d’accèsDescription

ActualHeight

en lecture seuleGets the rendered height of a FrameworkElement. (Hérité de FrameworkElement)

ActualStereo3DVideoPackingMode

en lecture seuleGets an enumeration value that determines the current value of stereo 3-D video frame-packing mode, accounting for other factors such as whether the media engine is ready for use.

ActualStereo3DVideoPackingModeProperty

en lecture seuleIdentifies the ActualStereo3DVideoPackingMode dependency property.

ActualWidth

en lecture seuleGets the rendered width of a FrameworkElement. (Hérité de FrameworkElement)

AllowDrop

en lecture/écritureGets or sets a value that determines whether this UIElement can be a drop target for purposes of drag-and-drop operations. (Hérité de UIElement)

AspectRatioHeight

en lecture seuleGets the height portion of the native aspect ratio of the media.

AspectRatioHeightProperty

en lecture seuleIdentifies the AspectRatioHeight dependency property.

AspectRatioWidth

en lecture seuleGets the width portion of the native aspect ratio of the media.

AspectRatioWidthProperty

en lecture seuleIdentifies the AspectRatioWidth dependency property.

AudioCategory

en lecture/écritureGets or sets a value that describes the purpose of the audio information in an audio stream.

AudioCategoryProperty

en lecture seuleIdentifies the AudioCategory dependency property.

AudioDeviceType

en lecture/écritureGets or sets a value that describes the primary usage of the device that is being used to play back audio.

AudioDeviceTypeProperty

en lecture seuleIdentifies the AudioDeviceType dependency property.

AudioStreamCount

en lecture seuleGets the number of audio streams that exist in the current media file.

AudioStreamCountProperty

en lecture seuleIdentifies the AudioStreamCount dependency property.

AudioStreamIndex

en lecture/écritureGets or sets the index of the audio stream that plays along with the video component. The collection of audio streams is composed at run time and represents all audio streams that are available in the media file.

AudioStreamIndexProperty

en lecture seuleIdentifies the AudioStreamIndex dependency property.

AutoPlay

en lecture/écritureGets or sets a value that indicates whether media will begin playback automatically when the Source property is set.

AutoPlayProperty

en lecture seuleIdentifies the AutoPlay dependency property.

Balance

en lecture/écritureGets or sets a ratio of volume across stereo speakers.

BalanceProperty

en lecture seuleIdentifies the Balance dependency property.

BaseUri

en lecture seuleGets a Uniform Resource Identifier (URI) that represents the base Uniform Resource Identifier (URI) for an XAML-constructed object at XAML load time. This property is useful for Uniform Resource Identifier (URI) resolution at run time. (Hérité de FrameworkElement)

BufferingProgress

en lecture seuleGets a value that indicates the current buffering progress.

BufferingProgressProperty

en lecture seuleIdentifies the BufferingProgress dependency property.

CacheMode

en lecture/écritureGets or sets a value that indicates that rendered content should be cached as a composited bitmap when possible. (Hérité de UIElement)

CanPause

en lecture seuleGets a value that indicates whether media can be paused if the Pause method is called.

CanPauseProperty

en lecture seuleIdentifies the CanPause dependency property.

CanSeek

en lecture seuleGets a value that indicates whether media can be repositioned by setting the value of the Position property.

CanSeekProperty

en lecture seuleIdentifies the CanSeek dependency property.

Clip

en lecture/écritureGets or sets the RectangleGeometry used to define the outline of the contents of a UIElement. (Hérité de UIElement)

CurrentState

en lecture seuleGets the status of this MediaElement.

CurrentStateProperty

en lecture seuleIdentifies the CurrentState dependency property.

DataContext

en lecture/écritureGets or sets the data context for a FrameworkElement when it participates in data binding. (Hérité de FrameworkElement)

DefaultPlaybackRate

en lecture/écritureGets or sets the default playback rate for the media engine. The playback rate applies when the user isn't using fast forward or reverse.

DefaultPlaybackRateProperty

en lecture seuleIdentifies the DefaultPlaybackRate dependency property.

DesiredSize

en lecture seuleGets the size that this UIElement computed during the measure pass of the layout process. (Hérité de UIElement)

Dispatcher

en lecture seuleGets the CoreDispatcher that this object is associated with. (Hérité de DependencyObject)

DownloadProgress

en lecture seuleGets a value that indicates the amount of download completed for content located on a remote server.

DownloadProgressOffset

en lecture seuleGets the offset of download progress, which is relevant in seek-ahead scenarios.

DownloadProgressOffsetProperty

en lecture seuleIdentifies the DownloadProgressOffset dependency property.

DownloadProgressProperty

en lecture seuleIdentifies the DownloadProgress dependency property.

FlowDirection

en lecture/écritureGets or sets the direction in which text and other UI elements flow within any parent element that controls their layout. This property can be set to either LeftToRight or RightToLeft. Setting FlowDirection to RightToLeft on any element sets the alignment to the right, the reading order to right-to-left and the layout of the control to flow from right to left. (Hérité de FrameworkElement)

Height

en lecture/écritureGets or sets the suggested height of a FrameworkElement. (Hérité de FrameworkElement)

HorizontalAlignment

en lecture/écritureGets or sets the horizontal alignment characteristics that are applied to a FrameworkElement when it is composed in a layout parent, such as a panel or items control. (Hérité de FrameworkElement)

IsAudioOnly

en lecture seuleGets a value that reports whether the current source media is an audio-only media file.

IsAudioOnlyProperty

en lecture seuleIdentifies the IsAudioOnly dependency property.

IsDoubleTapEnabled

en lecture/écritureGets or sets a value that determines whether the DoubleTapped event can originate from that element. (Hérité de UIElement)

IsHitTestVisible

en lecture/écritureGets or sets whether the contained area of this UIElement can return true values for hit testing. (Hérité de UIElement)

IsHoldingEnabled

en lecture/écritureGets or sets a value that determines whether the Holding event can originate from that element. (Hérité de UIElement)

IsLooping

en lecture/écritureGets or sets a value that describes whether the media source currently loaded in the media engine should automatically set the position to the media start after reaching its end.

IsLoopingProperty

en lecture seuleIdentifies the IsLooping dependency property.

IsMuted

en lecture/écritureGets or sets a value indicating whether the audio is muted.

IsMutedProperty

en lecture seuleIdentifies the IsMuted dependency property.

IsRightTapEnabled

en lecture/écritureGets or sets a value that determines whether the RightTapped event can originate from that element. (Hérité de UIElement)

IsStereo3DVideo

en lecture seuleGets a value that reports whether the current source media is a stereo 3-D video media file.

IsStereo3DVideoProperty

en lecture seuleIdentifies the IsStereo3DVideo dependency property.

IsTapEnabled

en lecture/écritureGets or sets a value that determines whether the Tapped event can originate from that element. (Hérité de UIElement)

Language

en lecture/écritureGets or sets localization/globalization language information that applies to a FrameworkElement, and also to all child elements of the current FrameworkElement in the object representation and in UI. (Hérité de FrameworkElement)

ManipulationMode

en lecture/écritureGets or sets the ManipulationModes value used for UIElement behavior and interaction with gestures. (Hérité de UIElement)

Margin

en lecture/écritureGets or sets the outer margin of a FrameworkElement. (Hérité de FrameworkElement)

Markers

en lecture seuleGets the collection of timeline markers associated with the currently loaded media file.

MaxHeight

en lecture/écritureGets or sets the maximum height constraint of a FrameworkElement. (Hérité de FrameworkElement)

MaxWidth

en lecture/écritureGets or sets the maximum width constraint of a FrameworkElement. (Hérité de FrameworkElement)

MinHeight

en lecture/écritureGets or sets the minimum height constraint of a FrameworkElement. (Hérité de FrameworkElement)

MinWidth

en lecture/écritureGets or sets the minimum width constraint of a FrameworkElement. (Hérité de FrameworkElement)

Name

en lecture/écritureGets or sets the identifying name of the object. When a XAML processor creates the object tree from XAML markup, run-time code can refer to the XAML-declared object by this name. (Hérité de FrameworkElement)

NaturalDuration

en lecture seuleGets the duration of the media file currently opened.

NaturalDurationProperty

en lecture seuleIdentifies the NaturalDuration dependency property.

NaturalVideoHeight

en lecture seuleGets the height of the video associated with the media.

NaturalVideoHeightProperty

en lecture seuleIdentifies the NaturalVideoHeight dependency property.

NaturalVideoWidth

en lecture seuleGets the width of the video associated with the media.

NaturalVideoWidthProperty

en lecture seuleIdentifies the NaturalVideoWidth dependency property.

Opacity

en lecture/écritureGets or sets the degree of the object's opacity. (Hérité de UIElement)

Parent

en lecture seuleGets the parent object of this FrameworkElement in the object tree. (Hérité de FrameworkElement)

PlaybackRate

en lecture/écritureGets or sets the playback rate ratio for the media engine.

PlaybackRateProperty

en lecture seuleIdentifies the PlaybackRate dependency property.

PlayToSource

en lecture seuleGets the information that is transmitted if the MediaElement is used for a "PlayTo" scenario.

PlayToSourceProperty

en lecture seuleIdentifies the PlayToSource dependency property.

PointerCaptures

en lecture seuleGets the set of all captured pointers, represented as Pointer values. (Hérité de UIElement)

Position

en lecture/écritureGets or sets the current position of progress through the media's playback time.

PositionProperty

en lecture seuleIdentifies the Position dependency property.

PosterSource

en lecture/écritureGets or sets the image source that is used for a placeholder image during MediaElement loading transition states.

PosterSourceProperty

en lecture seuleIdentifies the PosterSource dependency property.

Projection

en lecture/écritureGets or sets the perspective projection (3-D effect) to apply when rendering this element. (Hérité de UIElement)

ProtectionManager

en lecture/écritureGets or sets the dedicated object for media content protection that is associated with this MediaElement.

ProtectionManagerProperty

en lecture seuleIdentifies the ProtectionManager dependency property.

RealTimePlayback

en lecture/écritureGets or sets a value that configures the MediaElement for real-time communications scenarios.

RealTimePlaybackProperty

en lecture seuleIdentifies the RealTimePlayback dependency property.

RenderSize

en lecture seuleGets the final render size of a UIElement. (Hérité de UIElement)

RenderTransform

en lecture/écritureGets or sets transform information that affects the rendering position of a UIElement. (Hérité de UIElement)

RenderTransformOrigin

en lecture/écritureGets or sets the origin point of any possible render transform declared by RenderTransform, relative to the bounds of the UIElement. (Hérité de UIElement)

Resources

en lecture/écritureGets the locally defined resource dictionary. In XAML, you can establish resource items as child object elements of a frameworkElement.Resources property element, through XAML implicit collection syntax. (Hérité de FrameworkElement)

Source

en lecture/écritureGets or sets a media source on the MediaElement.

SourceProperty

en lecture seuleIdentifies the Source dependency property.

Stereo3DVideoPackingMode

en lecture/écritureGets or sets an enumeration value that determines the stereo 3-D video frame-packing mode for the current media source.

Stereo3DVideoPackingModeProperty

en lecture seuleIdentifies the Stereo3DVideoPackingMode dependency property.

Stereo3DVideoRenderMode

en lecture/écritureGets or sets an enumeration value that determines the stereo 3-D video render mode for the current media source.

Stereo3DVideoRenderModeProperty

en lecture seuleIdentifies the Stereo3DVideoRenderMode dependency property.

Style

en lecture/écritureGets or sets an instance Style that is applied for this object during layout and rendering. (Hérité de FrameworkElement)

Tag

en lecture/écritureGets or sets an arbitrary object value that can be used to store custom information about this object. (Hérité de FrameworkElement)

Transitions

en lecture/écritureGets or sets the collection of Transition style elements that apply to a UIElement. (Hérité de UIElement)

Triggers

en lecture seuleGets the collection of triggers for animations that are defined for a FrameworkElement. Not commonly used. (Hérité de FrameworkElement)

UseLayoutRounding

en lecture/écritureGets or sets a value that determines whether rendering for the object and its visual subtree should use rounding behavior that aligns rendering to whole pixels. (Hérité de UIElement)

VerticalAlignment

en lecture/écritureGets or sets the vertical alignment characteristics that are applied to a FrameworkElement when it is composed in a parent object such as a panel or items control. (Hérité de FrameworkElement)

Visibility

en lecture/écritureGets or sets the visibility of a UIElement. A UIElement that is not visible is not rendered and does not communicate its desired size to layout. (Hérité de UIElement)

Volume

en lecture/écritureGets or sets the media's volume.

VolumeProperty

en lecture seuleIdentifies the Volume dependency property.

Width

en lecture/écritureGets or sets the width of a FrameworkElement. (Hérité de FrameworkElement)

 

Remarques

Pour plus d'informations sur les performances liées à MediaElement, consultez Optimize media resources.

Les flux de données multimédias actifs signalent une propriété NaturalDuration de Int64.MaxValue.

Pour activer la lecture vidéo en plein écran, vous devez définir la Width et la Height de l'MediaElement sur les Window.Bounds de la fenêtre active. Utilisez en particulier Window.Current.Bounds.Width et Window.Current.Bounds.Height. La lecture pleine page ne profite pas des optimisations du système si vous définissez les dimensions d'un élément parent, telles qu'une grille ou un élément contenant au lieu d'un élément MediaElement.

Pour ne pas que l'affichage soit désactivé lorsque l'action utilisateur n'est plus détectée, par exemple lorsqu'une application lit la vidéo en plein écran, vous pouvez appeler DisplayRequest.RequestActive. Pour économiser de la puissance et l'autonomie des batteries, vous devez appeler DisplayRequest.RequestRelease pour publier la demande d'affichage lorsqu'elle n'est plus obligatoire. Consultez Exemple d'état d'alimentation d'affichage pour plus d'informations.

Exemples

Ce code crée un MediaElement avec la propriété AutoPlay définie explicitement sur true et la propriété Source défini sur le chemin d'accès d'un fichier vidéo qui est inclus dans l'application. Consultez Démarrage rapide : création d'une application de lecteur multimédia pour plus d'informations sur l'utilisation du MediaElement.


<MediaElement Source="Media/video1.mp4" AutoPlay="True" />


Configuration requise

Client minimal pris en charge

Windows 8 [Applications du Windows Store uniquement]

Serveur minimal pris en charge

Windows Server 2012 [Applications du Windows Store uniquement]

Espace de noms

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

Métadonnées

Windows.winmd

Voir aussi

Présentations
Présentation des applications Windows Store qui utilisent C# et Visual Basic
Présentation des applications Windows Store qui utilisent C++
Création UX pour les applications
Exemples
Exemple de lecture du média en XAML
Exemple « PlayTo » multimédia
Tâches
Démarrage rapide : création d'une application de lecteur multimédia
Démarrage rapide : vidéo et audio
Autres ressources
Formats audio et vidéo pris en charge
Optimiser les ressources multimédias

 

 

Afficher:
© 2015 Microsoft