Simple Title Player Application

By combining the Media Player Control with the TitleView control, you can easily create an application that allows the user to select a title from the Title server and watch it with the player. This simple sample uses HTML and VBScript to demonstrate one solution for playing the current selection in the TitleView control with the Media Player control.

Connecting to the Title Server

Start the page … Add text box for the server and a button to initiate the set server method.

<HTML>
<HEAD> <TITLE>Simple Title View and Media Player Example</TITLE> </HEAD>
<BODY>
<CENTER>Title Server: 
<INPUT TYPE="TEXT" NAME="SrvName" SIZE="25">
<INPUT TYPE="BUTTON" NAME="SetSrv" VALUE="Set Server">
<BR><BR>
Add the TitleView and MediaPlayer Controls

Use <OBJECT> tags to embed the controls in the page. Notice we added a param tag to indicate that the player should not begin playing the title when the file name is set.

<OBJECT ID="TitleView1" WIDTH=155 HEIGHT=240 CLASSID="CLSID:1E1BAAB1-3614-11D1-A5FE-00AA00BF93E3">
</OBJECT>

<OBJECT ID="MediaPlayer1" WIDTH=360 HEIGHT=240
  CLASSID="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95">
  <PARAM NAME="AutoStart" VALUE="FALSE">
</OBJECT>
Add Simple UI for the Player

Add the play and stop buttons to manipulate the Player control.

<BR><BR>
<INPUT TYPE="BUTTON" NAME="PlayBtn"  VALUE="    >     ">
<INPUT TYPE="BUTTON" NAME="StopBtn"   VALUE="    []    ">
<BR>
</CENTER>
</BODY>
Add the Subroutines to handle click events

The next step is to add four subroutines; three to process click events for the buttons we added to the page, and one to respond to the OnSelectionChanged event that is triggered when a title is selected from the TitleView control.

<SCRIPT LANGUAGE="VBScript">
<!--

' Connect to the specified Ttitle Server
Sub SetSrv_OnClick
  TitleView1.SetServer (SrvName.VALUE)
End Sub

' Set the file name based on title selected in TitleView 
Sub TitleView1_OnSelectionChanged( selection )
  If selection <> 0 Then
     strNewTitle = TitleView1.CurrentSelectionName 
     MediaPlayer1.FileName =  "nsm://" & SrvName.VALUE & "/" & strNewTitle
  End If
End Sub

' Play button click event.
' Make sure a title has been selected from TitleView    
Sub PlayBtn_OnClick
  If  MediaPlayer1.FileName = "" Then
      MsgBox "Select a Title to Play"
  Else
     MediaPlayer1.Play
  End If
End Sub

' *** Stop button click event. ***
Sub StopBtn_OnClick
   MediaPlayer1.Stop
End Sub

-->
</SCRIPT>
</HTML>
Putting it All Together

The preceding HTML and VBScript code fragments can be pasted together to create a working Web page. Bring the page up in your browser and type in the name of a title server on your intranet. After successfully connecting to the server, the available titles should appear in TitleView control.

© 1996-1998 Microsoft Corporation. All rights reserved.