Imports VBTrain.MediaObjects

Imports VBTrain.MediaObjects.WebPlayer

Imports System.IO

Imports System.Text

 

Public Class DemoPage1

    Inherits System.Web.UI.Page

 

    Private Const cr As String = "<br>"

 

' Object References deleted for clarity

 

' Web Designer Generated Code deleted for clarity

 

#Region "Event Handlers"

      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            If Me.IsPostBack Then

                  Call UpdateWebPlayer()

            End If

      End Sub

#End Region

 

#Region "Implementation Methods"

      Protected Sub UpdateWebPlayer()

            Dim enumString As String = PlayerTypeDropDown.SelectedItem.ToString

            Dim playerType As TypeOfPlayer = CType(System.Enum.Parse(GetType(TypeOfPlayer), enumString), TypeOfPlayer)

            Dim fileExtension As String = MediaDropDown.SelectedItem.ToString

            Dim fileTypeOkay As Boolean = True

            Dim statusText As New StringBuilder()

            Dim displayText As String = displayText_TextBox.Text

            Dim htmPlayerChoiceError As Boolean = False

            enumString = DisplayTextModeDropdown.SelectedItem.Text

            Dim textMode As DisplayTextModeEnum = CType(System.Enum.Parse(GetType(DisplayTextModeEnum), enumString), DisplayTextModeEnum)

 

            statusText.Append("<Strong>WebPlayer Control Information.</strong>")

            statusText.Append(cr)

            'Set DisplayText of control as streamed-in HTML file if necessary

            If fileExtension = "htm" Then

                  If playerType = TypeOfPlayer.Automatic Or playerType = TypeOfPlayer.TextOnly Then

                        Dim curPath As String = Request.PhysicalApplicationPath

                        Dim mediaPath As String = String.Concat(curPath, "media\")

                        Dim txtFile As String = String.Concat(mediaPath, "samplemedia.htm")

                        Dim sr As New StreamReader(txtFile)

                        Dim textResult As String

                        textResult = sr.ReadToEnd().ToString

                        displayText = textResult

                        playerType = TypeOfPlayer.TextOnly

                        statusText.Append("- Since file type was htm, this demo read-in the sample html file and set the DisplayText property of the web player to that html content.")

                        statusText.Append(cr)

                  Else

                        htmPlayerChoiceError = True

                        statusText.Append("- The demo only allows HTM file types if the Player Type is set to Automatic or Text.")

                        statusText.Append(cr)

                  End If

            End If

            If playerType = TypeOfPlayer.TextOnly And fileExtension <> "htm" Then

                  statusText.Append("- Since the PlayerType is text, the player shows text stored in its DisplayText property.")

                  statusText.Append(cr)

            End If

            fileTypeOkay = WebPlayer1.CheckFileType(fileExtension, playerType)

            If fileTypeOkay <> True Or htmPlayerChoiceError = True Then

                  playerType = TypeOfPlayer.TextOnly

                  displayText = "The file type is not playable in the selected player."

                  statusText.Append("- The demo code determined that the file type cannot be played in the player. The demo code then switched the PlayerType property to TextOnly and changed its DisplayText to the error message.")

                  statusText.Append(cr)

            End If

            With WebPlayer1

                  .DisplayTextMode = textMode

                  .MediaUrl = String.Concat("media/samplemedia.", MediaDropDown.SelectedItem.ToString)

                  .ShowControls = CBool(ShowControlsDropDown.SelectedItem.ToString)

                  .ShowDisplayScreen = CBool(ShowDisplayScreenDropDown.SelectedItem.ToString)

                  .HasLogo = CBool(HasLogoDropDown.SelectedItem.ToString)

                  .WillLoop = CBool(WillLoopDropDown.SelectedItem.ToString)

                  .Volume = CInt(VolumeDropDown.SelectedItem.ToString)

                  .BackgroundColor = Color.FromName(BackgroundColorDropDown.SelectedItem.ToString)

                  .AutoStart = CBool(AutostartDropDown.SelectedItem.ToString)

                  .StretchToFit = CBool(StretchToFitDropDown.SelectedItem.ToString)

                  .DisplayText = displayText

                  .PlayerType = playerType

            End With

            Dim specificStatusText As String = getSpecificStatusText()

            statusText.Append(specificStatusText)

            statusLabel.Text = statusText.ToString

      End Sub

 

      Private Function getSpecificStatusText() As String

            Dim sb As New StringBuilder()

 

            With sb

                  If WebPlayer1.AutoStart = False And WebPlayer1.ShowControls = False Then

                        .Append("- Since the player has AutoStart set to False and ShowControls set to False, there is no way to start the media.")

                        .Append(cr)

                  End If

                  Select Case WebPlayer1.PlayerType

                        Case TypeOfPlayer.Automatic

                              .Append("- This is an Automatic PlayerType. The player is then chosen based on the file extension of the media to play. Choose a specific player type to learn more.")

                              .Append(cr)

                        Case TypeOfPlayer.Flash_Player_5, TypeOfPlayer.Flash_Player_6_mx

                              If WebPlayer1.AutoStart = False Then

                                    .Append("- The AutoStart property works well with Flash, but since Flash does not have a built-in Play button, this demo will just show you the first frame of the movie.")

                                    .Append(cr)

                              End If

                              If WebPlayer1.ShowControls = True Then

                                    .Append("- The ShowControls doesn't have an affect on the Flash player. Flash doesn't have any built in controls such as Play, Pause, and Stop.")

                                    .Append(cr)

                              End If

                              If WebPlayer1.StretchToFit = True Then

                                    .Append("- Stretch to fit has no effect on Flash files.")

                                    .Append(cr)

                              End If

                              .Append("- Volume settings only affect Windows Media Player.")

                        Case TypeOfPlayer.Real_Player_G2_or_Newer

                              If WebPlayer1.WillLoop = True Then

                                    .Append("- The WillLoop property has no effect on the Real Player.")

                                    .Append(cr)

                              End If

                              If WebPlayer1.HasMenu = True Then

                                    .Append("- The HasMenu property has no effect on the Real Player.")

                                    .Append(cr)

                              End If

                              If WebPlayer1.HasLogo = True Then

                                    .Append("- The HasLogo property determines if a logo displays while the file is being accessed. This has no effect on Windows Media Player version 6 and Real Player.")

                                    .Append(cr)

                              End If

                              If WebPlayer1.BackgroundColor.ToString <> "ffffff" Then

                                    .Append("- BackgroundColor property is most useful for Flash.")

                                    .Append(cr)

                              End If

                              .Append("- Volume settings only affect Windows Media Player.")

                        Case TypeOfPlayer.Windows_Media_Player_7or9

                              If WebPlayer1.HasLogo = True Then

                                    .Append("- The HasLogo property determines if a logo displays while the file is being accessed. This setting only controls Windows Media Player version 6 and Real Player.")

                                    .Append(cr)

                              End If

                              If WebPlayer1.BackgroundColor.ToString <> "ffffff" Then

                                    .Append("- BackgroundColor property is most useful for Flash.")

                                    .Append(cr)

                              End If

                  End Select

            End With

            Return sb.ToString

      End Function

 

#End Region

 

End Class