Bean Software
ASP.NET Source Code
     



ASP.NET Media Player Control - VB.Net Source Code

This listing contains VB.Net code for custom ASP.NET Media Player control. More about this control you can read at How to build ASP.NET Media Player Control. C# source code is also available here.

#Region "namespaces"
Imports System
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
#End Region
 
<DefaultProperty("MovieURL"), ToolboxData("<{0}:Media_Player_Control runat=server></{0}:Media_Player_Control>")> _
Public Class Media_Player_Control
    Inherits System.Web.UI.WebControls.WebControl
 
#Region "Default Property Values"
    Const DefaultMovieURL As String = ""
    Const DefaultAutoStart As Boolean = False
    Const DefaultBalance As Integer = 0
    Const DefaultCurrentPosition As Integer = 0
    Const DefaultEnableContextMenu As Boolean = True
    Const DefaultFullScreen As Boolean = False
    Const DefaultMute As Boolean = False
    Const DefaultPlayCount As Integer = 1
    Const DefaultRate As Single = 1.0
    Const DefaultStretchToFit As Boolean = False
    Const DefaultUIMode As Enumerations.PlayerMode = Enumerations.PlayerMode.Full
    Const DefaultVolume As Integer = -1
#End Region
 
#Region "Constructor"
    Public Sub New()
        'Default width and height of the player
        Me.Width = System.Web.UI.WebControls.Unit.Pixel(320)
        Me.Height = System.Web.UI.WebControls.Unit.Pixel(240)
    End Sub
#End Region
 
#Region "Public properties"
 
    <Bindable(True), Category("Settings"), Description("Absolute or relative URL to movie.")> _
    Property MovieURL() As String
        Get
            Dim s As String = ViewState("MovieURL")
            If s Is Nothing Then
                Return DefaultMovieURL
            Else
                Return s
            End If
        End Get
        Set(ByVal value As String)
            If value <> DefaultMovieURL Then
                ViewState("MovieURL") = value
            Else
                ViewState("MovieURL") = Nothing
            End If
        End Set
    End Property
 
    <Bindable(True), Category("Settings"), Description("Would movie play when page is loaded.")> _
    Property AutoStart() As Boolean
        Get
            Dim s As Boolean = ViewState("AutoStart")
            If s = Nothing Then
                Return DefaultAutoStart
            Else
                Return s
            End If
        End Get
        Set(ByVal value As Boolean)
            If value <> DefaultAutoStart Then
                ViewState("AutoStart") = value
            Else
                ViewState("AutoStart") = Nothing
            End If
        End Set
    End Property
 
    <Bindable(True), Category("Settings"), Description("Balance")> _
    Property Balance() As Integer
        Get
            Dim s As Integer = ViewState("Balance")
            If s = Nothing Then
                Return DefaultBalance
            Else
                Return s
            End If
        End Get
        Set(ByVal value As Integer)
            If value > 100 Then value = 100
            If value < -100 Then value = -100
            If value <> DefaultBalance Then
                ViewState("Balance") = value
            Else
                ViewState("Balance") = Nothing
            End If
        End Set
    End Property
 
    <Bindable(True), Category("Settings"), Description("Current postion.")> _
    Property CurrentPosition() As Integer
        Get
            Dim s As Integer = ViewState("CurrentPosition")
            If s = Nothing Then
                Return DefaultCurrentPosition
            Else
                Return s
            End If
        End Get
        Set(ByVal value As Integer)
            If value < 0 Then value = 0
            If value <> DefaultCurrentPosition Then
                ViewState("CurrentPosition") = value
            Else
                ViewState("CurrentPosition") = Nothing
            End If
        End Set
    End Property
 
    <Bindable(True), Category("Settings")> _
    Property EnableContextMenu() As Boolean
        Get
            Dim s As Boolean = ViewState("EnableContextMenu")
            If s = Nothing Then
                Return DefaultEnableContextMenu
            Else
                Return s
            End If
        End Get
        Set(ByVal value As Boolean)
            If value <> DefaultEnableContextMenu Then
                ViewState("EnablecontextMenu") = value
            Else
                viewState("EnablecontextMenu") = Nothing
            End If
        End Set
    End Property
 
    <Bindable(True), Category("Settings"), Description("Would movie be played in full screen.")> _
    Property FullScreen() As Boolean
        Get
            Dim s As Boolean = ViewState("FullScreen")
            If s = Nothing Then
                Return DefaultFullScreen
            Else
                Return s
            End If
        End Get
        Set(ByVal value As Boolean)
            If value <> DefaultFullScreen Then
                ViewState("FullScreen") = value
            Else
                viewstate("FullScreen") = Nothing
            End If
        End Set
    End Property
 
    <Bindable(True), Category("Settings"), Description("Play video without sound.")> _
    Property Mute() As Boolean
        Get
            Dim s As Boolean = ViewState("Mute")
            If s = Nothing Then
                Return DefaultMute
            Else
                Return s
            End If
        End Get
        Set(ByVal value As Boolean)
            If value <> DefaultMute Then
                ViewState("Mute") = value
            Else
                ViewState("Mute") = Nothing
            End If
        End Set
    End Property
 
    <Bindable(True), Category("Settings"), Description("How much times will video play.")> _
    Property PlayCount() As Integer
        Get
            Dim s As Integer = ViewState("PlayCount")
            If s = Nothing Then
                Return DefaultPlayCount
            Else
                Return s
            End If
        End Get
        Set(ByVal value As Integer)
            If value < 1 Then value = 1
            If value <> DefaultPlayCount Then
                ViewState("PlayCount") = value
            Else
                ViewState("PlayCount") = Nothing
            End If
        End Set
    End Property
 
    <Bindable(True), Category("Settings")> _
    Property Rate() As Single
        Get
            Dim s As Single = ViewState("Rate")
            If s = Nothing Then
                Return DefaultRate
            Else
                Return s
            End If
        End Get
        Set(ByVal value As Single)
            If value < 0.0 Then value = 1.0
            If value <> DefaultRate Then
                ViewState("Rate") = value
            Else
                ViewState("Rate") = Nothing
            End If
        End Set
    End Property
 
    <Bindable(True), Category("Settings")> _
    Property StretchToFit() As Boolean
        Get
            Dim s As Boolean = ViewState("StretchToFit")
            If s = Nothing Then
                Return DefaultStretchToFit
            Else
                Return s
            End If
        End Get
        Set(ByVal value As Boolean)
            If value <> DefaultStretchToFit Then
                ViewState("StretchToFit") = value
            Else
                ViewState("StretchToFit") = Nothing
            End If
        End Set
    End Property
 
    <Bindable(True), Category("Settings"), Description("Set how player will look like.")> _
    Property uiMode() As Enumerations.PlayerMode
        Get
            Dim s As Enumerations.PlayerMode = ViewState("uiMode")
            If s = Nothing Then
                Return DefaultUIMode
            Else
                Return s
            End If
        End Get
        Set(ByVal value As Enumerations.PlayerMode)
            If value <> DefaultUIMode Then
                ViewState("uiMode") = value
            Else
                ViewState("uiMode") = Nothing
            End If
        End Set
    End Property
 
    <Bindable(True), Category("Settings"), Description("Set sound volume")> _
    Property Volume() As Integer
        Get
            Dim s As Integer = ViewState("Volume")
            If s = Nothing Then
                Return DefaultVolume
            Else
                Return s
            End If
        End Get
        Set(ByVal value As Integer)
            If value <> DefaultVolume Then
                ViewState("Volume") = value
            Else
                ViewState("Volume") = Nothing
            End If
        End Set
    End Property
 
#End Region
 
#Region "Private functions"
    Private Function getPlayerMode() As String
        Select Case uiMode
            Case Enumerations.PlayerMode.Invisible
                Return "invisible"
            Case Enumerations.PlayerMode.Mini
                Return "mini"
            Case Enumerations.PlayerMode.None
                Return "none"
            Case Else
                Return "full"
        End Select
    End Function
#End Region
 
#Region "Render"
    <Description("Render control, depending of property values")> _
    Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)
        Dim content As StringBuilder = New StringBuilder
        Dim BrowserType As String = ""
        If Not Web.HttpContext.Current Is Nothing Then
            BrowserType = Web.HttpContext.Current.Request.Browser.Type
        End If
        If BrowserType.StartsWith("Netscape") = False Then
            ' It is design mode or Internet explorer web browser
            content.Append("<OBJECT width=""" & Width.ToString() & """ height=""" & Height.ToString() & _
            """ CLASSID=""CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"" VIEWASTEXT>" & vbCrLf)
            content.Append("<PARAM name=""autoStart"" value=""" & AutoStart & """>" & vbCrLf)
            content.Append("<PARAM name=""URL"" value=""" & MovieURL & """>" & vbCrLf)
            content.Append("<PARAM name=""enabled"" value=""" & Enabled & """>" & vbCrLf)
            content.Append("<PARAM name=""balance"" value=""" & Balance & """>" & vbCrLf)
            content.Append("<PARAM name=""currentPosition"" value=""" & CurrentPosition & """>" & vbCrLf)
            content.Append("<PARAM name=""enableContextMenu"" value=""" & EnableContextMenu & """>" & vbCrLf)
            content.Append("<PARAM name=""fullScreen"" value=""" & FullScreen & """>" & vbCrLf)
            content.Append("<PARAM name=""mute"" value=""" & Mute & """>" & vbCrLf)
            content.Append("<PARAM name=""playCount"" value=""" & PlayCount & """>" & vbCrLf)
            content.Append("<PARAM name=""rate"" value=""" & Rate & """>" & vbCrLf)
            content.Append("<PARAM name=""stretchToFit"" value=""" & StretchToFit & """>" & vbCrLf)
            content.Append("<PARAM name=""uiMode"" value=""" & getPlayerMode() & """>" & vbCrLf)
            If Volume >= 0 Then
                content.Append("<PARAM name=""volume"" value=""" & Volume & """>" & vbCrLf)
            End If
            content.Append("</OBJECT>")
        Else
            ' It is firefox web browser
            content.Append("<EMBED type=""video/x-ms-wmv"" width=""" & Me.Width.ToString() & """ height=""" & _
            Me.Height.ToString() & """ autostart=""" & AutoStart & """ URL=""" & MovieURL & """ enabled=""" & _
            Enabled & """ balance=""" & Balance & """ currentPosition=""" & CurrentPosition & _
            """ enableContextMenu=""" & EnableContextMenu & """ fullScreen=""" & FullScreen & """ mute=""" & _
            Mute & """ playCount=""" & PlayCount & """ rate=""" & Rate & """ stretchTofit=""" & StretchToFit & _
            """ uiMode=""" & uiMode & """")
            If Volume >= 0 Then
                content.Append(" volume=""" & Volume & """")
            End If
            content.Append(">")
        End If
        output.Write(content.ToString())
    End Sub
#End Region
 
End Class
 
#Region "Enumerations"
Namespace Enumerations
    <Description("Player mode can be Invisible, None, Mini and Full")> _
    Public Enum PlayerMode
        Invisible = 0
        None = 1
        Mini = 2
        Full = 3
    End Enum
End Namespace
#End Region


 

 


 

Tutorial toolbar:  Tell A Friend  |  Add to favorites  |  Feedback


 


Copyright © 2002 - 2024. Bean Software. All rights reserved.