Search code examples
asp.netvb.netjwplayer

Programmatically set JWPlayer to play file from database


I have a querystring on page load that I use to get the filename and thumbnail image for JWPlayer. It is not getting the filename or thumbname, however. There must be a reason why I can't get it over to my aspx page, from the VB code behind.See code:

Code Behind (VB):
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Dim videoName As String = Request.QueryString("FileName")
    Dim thumb As String = Request.QueryString("Thumb")
End Sub

And now I need to get these string variables into the .ASPX page to the JWplayer script, but they do not

.ASPX:
<div id='container'></div>
<script type="text/javascript" src="~/player/jwplayer.js</script>
<script type="text/javascript">
        jwplayer("container").setup({                
            file: videoName,
            flashplayer: '~/player/player.swf',
            volume: 35,
            width: 480,
            height: 270,
            skin: '~/player/skins/skin.zip',
            image: thumb,                
        })
</script>

Solution

  • This is ho I solved it

    Code Behind (VB):
    
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
       Dim videoName As String = Request.QueryString("FileName")
       Dim thumb As String = Request.QueryString("Thumb")
       Dim dur As String = Request.QueryString("Duration").ToString()
    
    
        txt1.Text = "~contents/published/" & videoName.ToString()
        txt2.Text = "~/contents/thumbs/" & thumb.ToString()
        txt3.Text = dur.ToString()
    
    End Sub
    

    Now to get the value of the query string to the JWPlayer javascript, I had to add a javascript function inside the JW script and I called it codeAddress(). This kind of documentation is NOT found on the LongTail website or tutorials or anywhere else on the internet that I have found.

    .ASPX:
    <script type="text/javascript">
            function codeAddress() {
                var dootoo = document.getElementById('<%=txt1.ClientID%>').value;
                var doothree = document.getElementById('<%=txt2.ClientID%>').value;
                var doofour = document.getElementById('<%=txt3.ClientID%>').value;
                jwplayer("container").setup({
                    duration: doofour,
                    file: dootoo,
                    flashplayer: '~/player/player.swf',
                    skin: "~/player/skins/newtubedark.zip",
                    volume: 35,
                    width: 685,
                    height: 385,
                    image: doothree,
    
                })
            }
            window.onload = codeAddress;
        </script>
    <asp:textbox id="txt1" runat="server" style="display:none;"></asp:textbox>
        <asp:textbox id="txt2" runat="server" style="display:none;"></asp:textbox>
        <asp:textbox id="txt3" runat="server" style="display:none;"></asp:textbox>