MediaPlayer 类

定义

为绘图提供媒体播放功能。Provides media playback for drawings.

public ref class MediaPlayer : System::Windows::Media::Animation::Animatable
public class MediaPlayer : System.Windows.Media.Animation.Animatable
type MediaPlayer = class
    inherit Animatable
    interface DUCE.IResource
Public Class MediaPlayer
Inherits Animatable
继承

示例

[如何:使用 System.windows.media.videodrawing> @ no__t 播放媒体-0How to: Play Media using a VideoDrawing

注解

尽管可以在 可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML) 中声明此类的实例,但不能在不使用代码的情况下加载和播放其媒体。Although you can declare an instance of this class in 可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML), you cannot load and play its media without using code. 若要只播放 XAMLXAML 中的媒体,请使用 @no__t。To play media in XAMLXAML only, use a MediaElement. 此外,如果在 XAMLXAML 中声明实例,则唯一可行的用途是填充 @no__t 属性的属性元素语法。Also, if you declare an instance in XAMLXAML, the only practical use is to fill property element syntax for the Player property.

使用应用程序分发媒体时,不可将媒体文件用作项目资源。When distributing media with your application, you cannot use a media file as a project resource. 在项目文件中,必须改为将媒体类型设置为 Content 并将 CopyToOutputDirectory 设置为 PreserveNewestAlwaysIn your project file, you must instead set the media type to Content and set CopyToOutputDirectory to PreserveNewest or Always.

MediaPlayer 可用于两种不同的模式,具体取决于驱动播放机:独立模式或时钟模式。MediaPlayer can be used in two different modes, depending on what is driving the player: independent mode or clock mode. 在独立模式下,MediaPlayer 类似于图像,通过 @no__t 1 方法打开的媒体将播放。In independent mode, the MediaPlayer is analogous to an image and the media opened through the Open method drives playback. 在时钟模式下,可以将 MediaPlayer 视为动画的目标,因此它将在控制播放的计时树中具有相应的 @no__t 1 和 @no__t 2 条目。In Clock mode, the MediaPlayer can be thought of as a target for an animation, and thus it will have corresponding Timeline and Clock entries in the Timing tree which controls playback. 有关媒体模式的详细信息,请参阅多媒体概述For more information on media modes, see the Multimedia Overview.

MediaPlayer 与 @no__t 不同,因为它不是可以直接添加到应用程序的 @no__t 2 的控件。MediaPlayer is different from a MediaElement in that it is not a control that can be added directly to the 用户界面 (UI)user interface (UI) of an application. 若要显示使用 MediaPlayer 加载的媒体,必须使用 @no__t 或 @no__t。To display media loaded using MediaPlayer, a VideoDrawing or DrawingContext must be used.

构造函数

MediaPlayer()

初始化 MediaPlayer 类的新实例。Initializes a new instance of the MediaPlayer class.

属性

Balance

获取或设置左右扬声器音量之间的平衡。Gets or sets the balance between the left and right speaker volumes.

BufferingProgress

获取为流内容完成的缓冲百分比。Gets the percentage of buffering completed for streaming content.

CanFreeze

获取一个值,该值指示是否可将对象变为不可修改。Gets a value that indicates whether the object can be made unmodifiable.

(继承自 Freezable)
CanPause

获取一个值,该值指示是否可暂停媒体。Gets a value indicating whether the media can be paused.

Clock

获取或设置与要播放的 MediaClock 关联的 MediaTimelineGets or sets the MediaClock associated with the MediaTimeline to be played.

DependencyObjectType

获取对此实例的 CLRCLR 类型进行包装的 DependencyObjectTypeGets the DependencyObjectType that wraps the CLRCLR type of this instance.

(继承自 DependencyObject)
Dispatcher

获取与此 Dispatcher 关联的 DispatcherObjectGets the Dispatcher this DispatcherObject is associated with.

(继承自 DispatcherObject)
DownloadProgress

获取位于远程服务器上的内容的下载进度百分比。Gets the percentage of download progress for content located at a remote server.

HasAnimatedProperties

获取一个值,该值指示一个或多个 AnimationClock 对象是否与此对象的任何依赖项属性相关联。Gets a value that indicates whether one or more AnimationClock objects is associated with any of this object's dependency properties.

(继承自 Animatable)
HasAudio

获取一个值,该值指示媒体是否具有音频输出。Gets a value that indicating whether the media has audio output.

HasVideo

获取一个值,该值指示媒体是否具有视频输出。Gets a value that indicates whether the media has video output.

IsBuffering

获取一个值,该值指示媒体是否正在缓冲。Gets a value that indicates whether the media is buffering.

IsFrozen

获取一个值,该值指示对象当前是否可修改。Gets a value that indicates whether the object is currently modifiable.

(继承自 Freezable)
IsMuted

获取一个值,该值指示媒体是否被静音。Gets a value that indicates whether the media is muted.

IsSealed

获取一个值,该值指示此实例当前是否为密封的(只读)。Gets a value that indicates whether this instance is currently sealed (read-only).

(继承自 DependencyObject)
NaturalDuration

获取媒体的自然持续时间。Gets the natural duration of the media.

NaturalVideoHeight

获取视频的像素高度。Gets the pixel height of the video.

NaturalVideoWidth

获取视频的像素宽度。Gets the pixel width of the video.

Position

获取或设置媒体的当前位置。Gets or sets the current position of the media.

ScrubbingEnabled

获取或设置一个值,该值指示是否启用了拖动播放。Gets or sets a value that indicates whether scrubbing is enabled.

Source

获取媒体 UriGets the media Uri.

SpeedRatio

获取或设置媒体的播放速率。Gets or sets the ratio of speed that media is played at.

Volume

获取或设置媒体的音量。Gets or sets the media's volume.

方法

ApplyAnimationClock(DependencyProperty, AnimationClock)

AnimationClock 应用到指定的 DependencyPropertyApplies an AnimationClock to the specified DependencyProperty. 如果该属性已进行动画处理,则使用 SnapshotAndReplace 切换行为。If the property is already animated, the SnapshotAndReplace handoff behavior is used.

(继承自 Animatable)
ApplyAnimationClock(DependencyProperty, AnimationClock, HandoffBehavior)

AnimationClock 应用到指定的 DependencyPropertyApplies an AnimationClock to the specified DependencyProperty. 如果该属性已进行动画处理,则使用指定的 HandoffBehaviorIf the property is already animated, the specified HandoffBehavior is used.

(继承自 Animatable)
BeginAnimation(DependencyProperty, AnimationTimeline)

将动画应用于指定 DependencyPropertyApplies an animation to the specified DependencyProperty. 动画会在呈现下一帧时启动。The animation is started when the next frame is rendered. 如果指定属性已进行动画处理,则使用 SnapshotAndReplace 切换行为。If the specified property is already animated, the SnapshotAndReplace handoff behavior is used.

(继承自 Animatable)
BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior)

将动画应用于指定 DependencyPropertyApplies an animation to the specified DependencyProperty. 动画会在呈现下一帧时启动。The animation is started when the next frame is rendered. 如果指定的属性已进行动画处理,则使用指定的 HandoffBehaviorIf the specified property is already animated, the specified HandoffBehavior is used.

(继承自 Animatable)
CheckAccess()

确定调用线程是否可以访问此 DispatcherObjectDetermines whether the calling thread has access to this DispatcherObject.

(继承自 DispatcherObject)
ClearValue(DependencyProperty)

清除属性的本地值。Clears the local value of a property. 要清除的属性由 DependencyProperty 标识符指定。The property to be cleared is specified by a DependencyProperty identifier.

(继承自 DependencyObject)
ClearValue(DependencyPropertyKey)

清除只读属性的本地值。Clears the local value of a read-only property. 要清除的属性由 DependencyPropertyKey 指定。The property to be cleared is specified by a DependencyPropertyKey.

(继承自 DependencyObject)
Clone()

创建此 Animatable 的可修改克隆,从而深度复制此对象的值。Creates a modifiable clone of this Animatable, making deep copies of this object's values. 在复制此对象的依赖项属性时,此方法会复制资源引用和数据绑定(但它们可能不再解析),但不复制动画或其当前值。When copying this object's dependency properties, this method copies resource references and data bindings (but they might no longer resolve) but not animations or their current values.

(继承自 Animatable)
CloneCore(Freezable)

使此实例成为指定 MediaPlayer 的深层副本。Makes this instance a deep copy of the specified MediaPlayer. 在复制依赖项属性时,此方法会复制资源引用和数据绑定(但可能不再解析),但不复制动画或其当前值。When copying dependency properties, this method copies resource references and data bindings (but they might no longer resolve) but not animations or their current values.

CloneCurrentValue()

使用 Freezable 的当前值创建其可修改复本(深层副本)。Creates a modifiable clone (deep copy) of the Freezable using its current values.

(继承自 Freezable)
CloneCurrentValueCore(Freezable)

使用当前的属性值使此实例成为指定 MediaPlayer 的可修改深层复制。Makes this instance a modifiable deep copy of the specified MediaPlayer using current property values. 不复制资源引用、数据绑定和动画,而是复制其当前值。Resource references, data bindings, and animations are not copied, but their current values are.

Close()

关闭基础媒体。Closes the underlying media.

CoerceValue(DependencyProperty)

对指定依赖属性的值进行强制。Coerces the value of the specified dependency property. 通过对调用方 DependencyObject 上存在的依赖属性的属性元数据中所指定的任何 CoerceValueCallback 函数进行调用来完成此操作。This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.

(继承自 DependencyObject)
CreateInstance()

初始化 Freezable 类的新实例。Initializes a new instance of the Freezable class.

(继承自 Freezable)
CreateInstanceCore()

创建一个新的 MediaPlayer 实例。Creates a new MediaPlayer instance.

Equals(Object)

确定提供的 DependencyObject 是否等效于当前 DependencyObjectDetermines whether a provided DependencyObject is equivalent to the current DependencyObject.

(继承自 DependencyObject)
Freeze()

使当前对象不可修改,并且将其 IsFrozen 属性设置为 trueMakes the current object unmodifiable and sets its IsFrozen property to true.

(继承自 Freezable)
FreezeCore(Boolean)

使此 Animatable 对象成为不可修改的对象,或确定是否可使其成为不可修改的对象。Makes this Animatable object unmodifiable or determines whether it can be made unmodifiable.

(继承自 Animatable)
GetAnimationBaseValue(DependencyProperty)

返回指定的 DependencyProperty 的未经过动画处理的值。Returns the non-animated value of the specified DependencyProperty.

(继承自 Animatable)
GetAsFrozen()

使用基(未经过动画处理的)属性值创建 Freezable 的冻结副本。Creates a frozen copy of the Freezable, using base (non-animated) property values. 由于副本已冻结,因此将通过引用复制任何冻结的子对象。Because the copy is frozen, any frozen sub-objects are copied by reference.

(继承自 Freezable)
GetAsFrozenCore(Freezable)

使此实例成为指定的 MediaPlayer 对象的克隆。Makes this instance a clone of the specified MediaPlayer object.

GetCurrentValueAsFrozen()

使用当前属性值创建 Freezable 的冻结副本。Creates a frozen copy of the Freezable using current property values. 由于副本已冻结,因此将通过引用复制任何冻结的子对象。Because the copy is frozen, any frozen sub-objects are copied by reference.

(继承自 Freezable)
GetCurrentValueAsFrozenCore(Freezable)

使当前实例成为指定的 Freezable 的冻结复本。Makes the current instance a frozen clone of the specified Freezable. 如果对象具有动画依赖属性,则复制其当前的动画值。If the object has animated dependency properties, their current animated values are copied.

(继承自 Freezable)
GetHashCode()

获取此 DependencyObject 的哈希代码。Gets a hash code for this DependencyObject.

(继承自 DependencyObject)
GetLocalValueEnumerator()

创建一个专用的枚举数,用于确定哪些依赖项属性在此 DependencyObject 上具有以本地方式设置的值。Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

(继承自 DependencyObject)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
GetValue(DependencyProperty)

DependencyObject 的此实例返回依赖属性的当前有效值。Returns the current effective value of a dependency property on this instance of a DependencyObject.

(继承自 DependencyObject)
InvalidateProperty(DependencyProperty)

重新评估指定依赖属性的有效值。Re-evaluates the effective value for the specified dependency property.

(继承自 DependencyObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnChanged()

修改当前 Freezable 对象时调用。Called when the current Freezable object is modified.

(继承自 Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject)

确保为刚刚设置的 DependencyObjectType 数据成员建立适当的上下文指针。Ensures that appropriate context pointers are established for a DependencyObjectType data member that has just been set.

(继承自 Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty)

此成员支持 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基础结构,但不能在代码中直接使用。This member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.

(继承自 Freezable)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

重写 OnPropertyChanged(DependencyPropertyChangedEventArgs)DependencyObject 实现,以同时调用任何响应类型 Freezable 不断变化的依赖属性的 Changed 处理程序。Overrides the DependencyObject implementation of OnPropertyChanged(DependencyPropertyChangedEventArgs) to also invoke any Changed handlers in response to a changing dependency property of type Freezable.

(继承自 Freezable)
Open(Uri)

打开给定的 Uri 以进行媒体播放。Opens the given Uri for media playback.

Pause()

暂停媒体播放。Pauses media playback.

Play()

从当前 Position 播放媒体。Plays media from the current Position.

ReadLocalValue(DependencyProperty)

如果存在,则返回依赖属性的本地值。Returns the local value of a dependency property, if it exists.

(继承自 DependencyObject)
ReadPreamble()

确保正在从有效线程中访问 MediaPlayer。Ensures that the MediaPlayer is being accessed from a valid thread.

SetCurrentValue(DependencyProperty, Object)

设置依赖属性的值而不更改其值源。Sets the value of a dependency property without changing its value source.

(继承自 DependencyObject)
SetValue(DependencyProperty, Object)

设置依赖属性的本地值,该值由其依赖属性标识符指定。Sets the local value of a dependency property, specified by its dependency property identifier.

(继承自 DependencyObject)
SetValue(DependencyPropertyKey, Object)

设置一个只读依赖属性的本地值,该值由依赖属性的 DependencyPropertyKey 标识符指定。Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

(继承自 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

返回一个值,该值指示序列化进程是否应序列化所提供的依赖属性的值。Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.

(继承自 DependencyObject)
Stop()

停止媒体播放。Stops media playback.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)
VerifyAccess()

强制调用线程具有此 DispatcherObject 的访问权限。Enforces that the calling thread has access to this DispatcherObject.

(继承自 DispatcherObject)
WritePostscript()

引发 FreezableChanged 事件并调用其 OnChanged() 方法。Raises the Changed event for the Freezable and invokes its OnChanged() method. Freezable 派生的类应在修改的类成员不存储为依赖属性的任何 API 的末尾调用此方法。Classes that derive from Freezable should call this method at the end of any API that modifies class members that are not stored as dependency properties.

(继承自 Freezable)
WritePreamble()

验证 MediaPlayer 是否未被冻结,并且是否正在从有效的线程上下文中访问它。Verifies that the MediaPlayer is not frozen and that it is being accessed from a valid threading context.

事件

BufferingEnded

当完成缓冲时发生。Occurs when buffering has finished.

BufferingStarted

当开始缓冲时发生。Occurs when buffering has started.

Changed

在修改 Freezable 或其包含的对象时发生。Occurs when the Freezable or an object it contains is modified.

(继承自 Freezable)
MediaEnded

在媒体完成播放时发生。Occurs when the media has finished playback.

MediaFailed

当遇到错误时发生。Occurs when an error is encountered.

MediaOpened

在打开媒体时发生。Occurs when the media is opened.

ScriptCommand

当在媒体中遇到脚本命令时发生。Occurs when a script command has been encountered within the media.

适用于

另请参阅