ScriptCommand using System.Windows.Media.MediaPlayer and Windows Media Player

Using Scriptcommand in .net

Using ScriptCommand in System.Windows.Media.MediaPlayer and Windows Media Player

Some times we want to display caption/subtitle when we play music or movies, for this we have scriptcommand in Windows Media Player and System.Windows.Media.MediaPlayer

Windows Media Player Control have a property to set the sami *.smi file, but System.Windows.Media.MediaPlayer does not have a property for setting the sami *.smi file. You can also set the sami *.smi using sami param in the url (media-url?sami=Sami-url), this sami param can also be used in the url using System.Windows.Media.MediaPlayer. This can only be used when loaded from web.

vb.net code

Windows Media player control:

    
    ' Set media and sami *.smi using windows media player control 
    Private Sub OpenWmp(ByVal Mediaurl As String, ByVal SamiUrl As String)
        WMP1.URL = Mediaurl
        WMP1.closedCaption.SAMIFileName = SamiUrl
    End Sub

    Private Sub WMP1_ScriptCommand(sender As Object, e As AxWMPLib._WMPOCXEvents_ScriptCommandEvent) Handles WMP1.ScriptCommand
       
            Select Case e.scType.ToLower

                    ' Text are used as command in sami *.smi files.
                Case "text"
                    ' Sami are html elements.
                    Me.WebBr1.DocumentText = e.param

                    ' Caption is used as default command in wma, asf, wmv but any command name can be used.
                Case "caption"
                    ' caption can be both plain text and html.
                    Me.WebBr1.DocumentText = e.param
            End Select

    End Sub

 

System.Windows.Media.MediaPlayer:

    
    ' Set media and sami *.smi using System.Windows.Media.MediaPlayer 
    Private Sub OpenNetMediaPlayer(ByVal Mediaurl As String, ByVal SamiUrl As String)
        ' can only be used for web and not local files and only one (1) param can be used
        Me.Netplayer.Open(New Uri(Mediaurl & "?Sami=" & Samiurl))
    End Sub

    Private Sub Netplayer_ScriptCommand(sender As Object, e As System.Windows.Media.MediaScriptCommandEventArgs) Handles Netplayer.ScriptCommand
       
            Select Case e.ParameterType.ToLower
                    ' Text command is used for sami *.smi files.
                Case "text"
                    ' Sami are html elements
                    Me.WebBr1.DocumentText = e.ParameterValue
                    ' Caption is used as default command in wma, asf, wmv but any command name can be used
                Case "caption"
                    ' caption can be both plain text and html.
                    Me.WebBr1.DocumentText = e.ParameterValue
            End Select

       
    End Sub

 

Enable script commands in Windows Media Player or not?

If scriptcommand is enabled in Windows Media Player will players using Windows Media player control or System.Windows.Media.MediaPlayer look for a sami *.smi file at the location where the media is loaded from local or web file. If not enabled most sami *.smi location be set using code.

Sample project

Download Sample