Class PlaySoundAction
An action that will play a sound to completion.
public class PlaySoundAction : TriggerAction<DependencyObject>, IAnimatable, IAttachedObject
- Inheritance
-
PlaySoundAction
- Implements
- Inherited Members
- Extension Methods
Remarks
This action is intended for use with short sound effects that don't need to be stopped or controlled. If you're trying to create a music player or game, it may not meet your needs.
Constructors
PlaySoundAction()
Initializes a new instance of the PlaySoundAction class.
public PlaySoundAction()
Fields
SourceProperty
public static readonly DependencyProperty SourceProperty
Field Value
VolumeProperty
public static readonly DependencyProperty VolumeProperty
Field Value
Properties
Source
A Uri defining the location of the sound file. This is used to set the source property of the MediaElement. This is a dependency property.
public Uri Source { get; set; }
Property Value
Remarks
The sound can be any file format supported by MediaElement. In the case of a video, it will play only the audio portion.
Volume
Control the volume of the sound. This is used to set the Volume property of the MediaElement. This is a dependency property.
public double Volume { get; set; }
Property Value
Methods
Invoke(object)
This method is called when some criteria are met and the action should be invoked.
protected override void Invoke(object parameter)
Parameters
parameter
object
Remarks
Each invocation of the Action plays a new sound. Although the implementation is subject-to-change, the caller should anticipate that this will create a new MediaElement that will be cleaned up when the sound completes or if the media fails to play.
SetMediaElementProperties(MediaElement)
When the action is invoked, this method is used to customize the dynamically created MediaElement.
protected virtual void SetMediaElementProperties(MediaElement mediaElement)
Parameters
mediaElement
MediaElement
Remarks
This method may be useful for Action authors who wish to extend PlaySoundAction. If you want to control the MediaElement Balance property, you could inherit from PlaySoundAction and override this method.