MediaElement.MediaOpened MediaElement.MediaOpened MediaElement.MediaOpened MediaElement.MediaOpened Event

Definition

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

public : event RoutedEventHandler MediaOpened
// Register
event_token MediaOpened(RoutedEventHandler const& handler) const;

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

// Revoke with event_revoker
MediaOpened_revoker MediaOpened(auto_revoke_t, RoutedEventHandler const& handler) const;
public event RoutedEventHandler MediaOpened
Public Event MediaOpened As RoutedEventHandler
<MediaElement MediaOpened="eventhandler" .../>

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.