Share via


MediaElement.MediaOpened Event

Definition

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

// Register
event_token MediaOpened(RoutedEventHandler const& handler) const;

// Revoke with event_token
void MediaOpened(event_token const* cookie) const;

// Revoke with event_revoker
MediaElement::MediaOpened_revoker MediaOpened(auto_revoke_t, RoutedEventHandler const& handler) const;
public event RoutedEventHandler MediaOpened;
function onMediaOpened(eventArgs) { /* Your code */ }
mediaElement.addEventListener("mediaopened", onMediaOpened);
mediaElement.removeEventListener("mediaopened", onMediaOpened);
- or -
mediaElement.onmediaopened = onMediaOpened;
Public Custom Event MediaOpened As RoutedEventHandler 
<MediaElement MediaOpened="eventhandler" .../>

Event Type

Examples

The following code shows how to determine if a media stream is a live stream.

private void media_MediaOpened(object sender, RoutedEventArgs e)
{
    bool isLive = IsLiveStream(sender as MediaElement);
}

private bool IsLiveStream(MediaElement media)
{
    bool isLive = false;

    if (media.NaturalDuration.TimeSpan.Ticks == Int64.MaxValue)
    {
       isLive = true;
    }

    return isLive;
}

Remarks

Live media streams report a NaturalDuration of Int64.MaxValue.

Any calls to Play, Pause, and Stop methods that occur before the MediaOpened event is raised are ignored.

Applies to