Share via


MediaOpened

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Occurs when the media stream has been validated and opened, and the file headers have been read.

<object MediaOpened="eventhandlerFunction"  .../>
[token = ]object.AddEventListener("MediaOpened", eventhandlerFunction)

Arguments

AddEventListener Parameters

token

integer

A token that is returned from the function, which you can optionally retain as a variable. If you intend to call RemoveEventListener to remove the handler, you will need this token.

eventhandlerFunction

object

The name of your event handler function as it is defined in script. When used as an AddEventListener parameter, quotation marks around the function name are not required. (See the "Remarks" section.)

Event Handler Parameters

sender

object

The object that invoked the event.

eventArgs

object

This parameter is always set to null.

Managed Equivalent

MediaOpened

Remarks

A MediaElement object generally has two types of properties:

  • Properties that are settable and that declare the appearance or behavior of the MediaElement.

  • Read-only properties that report on the characteristics of the current Source file that is loaded by the MediaElement.

Properties in this second category will not contain valid values until the MediaElement raises the MediaOpened event. The following is a list of MediaElement properties that will not be valid until after MediaOpened is raised by that element.

In addition, the Position property will be null before the MediaOpened event. However, Position is different from the other properties in the second group because it is settable. You should not attempt to set Position until MediaOpened is raised. You also should not set an initial Position value in XAML.

If the AutoPlay property is set to false, the media will be paused when the MediaOpened event occurs.

You can also add handlers in script by using a quoted string for the event handler name, as follows:

object.AddEventListener("MediaOpened", "eventhandlerFunction")

This syntax also returns a token. However, the token is not an absolute requirement for removing the handler in cases where the handler was added by using a quoted string. For details, see RemoveEventListener.

Applies To

MediaElement