Solved

Programmically set JWPlayer to playa file from database

Posted on 2012-03-31
6
1,199 Views
Last Modified: 2012-06-02
I have jwplayer and I need to to play a video file selected from database. I can only find where you put the file in manually to play such as file: "/output/video.mp4"

I need it to be as follows: and this does not work for some reason:

Dim strAuthor, strTitle, strWidth, strHeight, strDuration, strOriginalFile, strFLVFile, strImageFile, strUploadTime, strViews, strVideoType, strTags As String
    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strConn As String = "Data Source=MyDataSource"
        Dim MySQL As String = "Select * From Videos Where ID = 56"
        Dim Conn As New SqlConnection(strConn)
        Dim objDR As SqlDataReader
        Dim Cmd As New SqlCommand(MySQL, Conn)
        Conn.Open()
        objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
        While objDR.Read()
            strAuthor = objDR("Author").ToString()
            strTitle = objDR("Title").ToString()
            strWidth = objDR("Width").ToString()
            strHeight = objDR("Height").ToString()
            strDuration = objDR("Duration").ToString()
            strOriginalFile = objDR("OriginalFile").ToString()
            strFLVFile = objDR("FLVFile").ToString()
            strImageFile = objDR("ImageFile").ToString()
            strUploadTime = objDR("UploadTime").ToString()
            strViews = objDR("Views").ToString()
            strVideoType = objDR("VideoType").ToString()
            strTags = objDR("Tags").ToString()
        End While
        Conn.Close()
       
        msgs.Text = "Output/" & strFLVFile.ToString()
        
    End Sub

HTML...

<div id="container">Loading the player ...</div>    
        <script type="text/javascript">
        jwplayer("container").setup({
            flashplayer: "JWPlayer/player.swf",
            height: 350,
            width: 640,
            autostart: true,
            file: filename    <====== need this from sql data reader above "strFLVFileName"
            image: "JWPlayer/preview.jpg"
         
        });    
     </script>

Open in new window

0
Comment
Question by:mlg101
  • 3
6 Comments
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
use a placeholder to inject the player into your aspx page (scroll down to the solution provided):
http://forums.asp.net/t/1736036.aspx/1
0
 
LVL 1

Author Comment

by:mlg101
Comment Utility
That is fine but I can't see where to put that in the context of what I have: an aspx page with code behind and html
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
Comment Utility
to get the filename from datareader to your aspx page u can set a global variable using the following code:

msgs.Text = "Output/" & strFLVFile.ToString()
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "strFLVFileName", msgs.Text);

Open in new window


this line will render the page with a global variable called strFLVFileName with the requested filename value.
then in your aspx page simply assign this variable to the jwplayer:

jwplayer("container").setup({
            flashplayer: "JWPlayer/player.swf",
            height: 350,
            width: 640,
            autostart: true,
            file: strFLVFileName,
            image: "JWPlayer/preview.jpg"

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
to verify that the variable was indeed exists and was set to the filename from the datareader u can view the source of the page once it was loaded and look for a variable called strFLVFileName and check its value.
0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
Comment Utility
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now