Share via


MediaPlayer.OnClientMediaOpened Property

Gets or sets the name of the client JavaScript function (event handler) that is called when the Sys.UI.Silverlight.MediaPlayer.mediaOpened event occurs.

Namespace:  System.Web.UI.SilverlightControls
Assembly:  System.Web.Silverlight (in System.Web.Silverlight.dll)

Syntax

'Declaration
<BindableAttribute(True)> _
Public Overridable Property OnClientMediaOpened As String
    Get
    Set
'Usage
Dim instance As MediaPlayer
Dim value As String

value = instance.OnClientMediaOpened

instance.OnClientMediaOpened = value
[BindableAttribute(true)]
public virtual string OnClientMediaOpened { get; set; }

Property Value

Type: System.String
The name of the JavaScript function that is called when the media source opens.

Remarks

The client mediaOpened client event occurs at runtime when the media file is finishes loading.

If the Source property is set to an .asx playlist with more than one media file or the media definition file specified by the MediaDefinition property contains more than one media file, a mediaOpened client event occurs each time that a media file is loaded.

Examples

The following example demonstrates how to set the name of a JavaScript function to run when the media file opens at runtime and the client mediaOpened event occurs. This code example is part of a larger example provided for the Sys.UI.Silverlight.MediaPlayer class.

The markup shows the OnClientMediaOpened property on MediaPlayer server control indicating that mediaOpened is the name of the JavaScript function to run when a mediaOpened client event occurs at runtime.

<asp:MediaPlayer ID="MediaPlayer1" runat="server" Height="300px" Width="400px" 
    OnClientChapterSelected="chapterSelected" 
    OnClientChapterStarted="chapterStarted" 
    OnClientCurrentStateChanged="currentStateChanged" 
    OnClientMarkerReached="markerReached" 
    OnClientMediaEnded="mediaEnded" 
    OnClientMediaFailed="mediaFailed" 
    OnClientMediaOpened="mediaOpened" 
    OnClientVolumeChanged="volumeChanged"
    onPluginFullScreenChanged="fullScreenChanged"
    MediaSource="../media/expressionstudio.wmv" AutoPlay="True" 
    MediaSkinSource="../skins/Professional.xaml">
    <Chapters>
        <asp:MediaChapter Position="5" Title="A New Start" ThumbnailSource="../images/Water lilies.jpg" />
        <asp:MediaChapter Position="22" Title="More Things" ThumbnailSource="../images/Sunset.jpg"/>
        <asp:MediaChapter Position="54" Title="Final Thoughts" ThumbnailSource="../images/Blue hills.jpg" />
    </Chapters>
</asp:MediaPlayer>
<asp:MediaPlayer ID="MediaPlayer1" runat="server" Height="300px" Width="400px" 
    OnClientChapterSelected="chapterSelected" 
    OnClientChapterStarted="chapterStarted" 
    OnClientCurrentStateChanged="currentStateChanged" 
    OnClientMarkerReached="markerReached" 
    OnClientMediaEnded="mediaEnded" 
    OnClientMediaFailed="mediaFailed" 
    OnClientMediaOpened="mediaOpened" 
    OnClientVolumeChanged="volumeChanged"
    onPluginFullScreenChanged="fullScreenChanged"
    MediaSource="../media/expressionstudio.wmv" AutoPlay="True" 
    MediaSkinSource="../skins/Professional.xaml">
    <Chapters>
        <asp:MediaChapter Position="5" Title="A New Start" ThumbnailSource="../images/Water lilies.jpg" />
        <asp:MediaChapter Position="22" Title="More Things" ThumbnailSource="../images/Sunset.jpg"/>
        <asp:MediaChapter Position="54" Title="Final Thoughts" ThumbnailSource="../images/Blue hills.jpg" />
    </Chapters>
</asp:MediaPlayer>

The client script shows the mediaOpened JavaScript function.

function mediaOpened(sender, args) {
    var currentPosition = sender.get_position();
    var textMessage = String.format("mediaOpened event: position {0} seconds", currentPosition);
    ta.innerText +=  '\r\n' + textMessage; 
}
function mediaOpened(sender, args) {
    var currentPosition = sender.get_position();
    var textMessage = String.format("mediaOpened event: position {0} seconds", currentPosition);
    ta.innerText +=  '\r\n' + textMessage; 
}

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference

MediaPlayer Class

MediaPlayer Members

System.Web.UI.SilverlightControls Namespace

MediaSource

MediaDefinition