locked
view video from drop down list (Visual Studio 2010) RRS feed

  • Question

  • User-1058836992 posted

    I'm having some trouble getting videos to play when I select them from a drop down list.  I want to be able to select a video from the drop down list and play it using ASPNetVideo:RealPlayer (RealPlayer).  The videos are uploaded to a database and put into the drop down list and I can't get them to play.
    I'm using Visual Studio 2010 and Language: VB
    Can anyone help me with this problem.

    here is my code:

    <%@ Page Language="VB" Debug="true" %>
    
    <%@ Register Assembly="ASPNetVideo.NET4" Namespace="ASPNetVideo" TagPrefix="ASPNetVideo" %>
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%@ Import Namespace="System.Web.UI" %>
    <script runat="server">
    
        Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            If Not IsPostBack Then
                BindGrid()
            End If
        End Sub
     
        Private Sub BindGrid()
            Dim strConnString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
            Using con As New SqlConnection(strConnString)
                Using cmd As New SqlCommand()
                    cmd.CommandText = "select id, title, description, FileName from UploadVideo"
                    cmd.Connection = con
                    con.Open()
                    'DataList1.DataSource = cmd.ExecuteReader()
                    'DataList1.DataBind()
                    con.Close()
                End Using
            End Using
        End Sub
    
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim sCurrentFilename As String
           
           
            For Each r As GridViewRow In GridView1.Rows
                If DropDownList1.SelectedValue = r.Cells.Item(1).Text Then
               
               
               
                   
               
                    sCurrentFilename = r.Cells.Item(3).Text
                    RealPlayer1.VideoURL = sCurrentFilename
                    'RealPlayer1.VideoURL = "C:\upload\index_heat_rate.mp4"
                    'RealPlayer1.VideoURL = "~/videos/test_upload_video.mp4"
                   
                                                 
                End If
               
            Next
               
        End Sub
    </script>
    
    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
        <title>List of Videos</title>
    </head>
    <body>
        <form id="form1" runat="server">
    <h2>List of Videos</h2>
    <hr />
    <br />
    
    
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="title" HeaderText="title" SortExpression="title" />
                <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"
                    ReadOnly="True" SortExpression="id" />
                <asp:BoundField DataField="description" HeaderText="description"
                    SortExpression="description" />
                <asp:BoundField DataField="FileName" HeaderText="FileName"
                    SortExpression="FileName" />
            </Columns>
        </asp:GridView>
        <asp:DropDownList ID="DropDownList1" runat="server"
            DataSourceID="SqlDataSource1" DataTextField="title" DataValueField="id">
        </asp:DropDownList>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:Training VideosConnectionString %>"
            SelectCommand="SELECT [title], [id], [description], [FileName] FROM [UploadVideo]">
        </asp:SqlDataSource>
        <ItemTemplate>
            <u>
                <%# Eval("description")%></u>
            <hr />
           
    
            <a class="player" style="height: 300px; width: 300px; display: block" href='<%# Eval("Id", "FileCS.ashx?Id={0}") %>'>
            </a>
        </ItemTemplate>
       
        <ASPNetVideo:RealPlayer ID="RealPlayer1" runat=server AutoPlay="False"  
             Width="600px" Height="500px"></ASPNetVideo:RealPlayer>
    
         
        </form>
    
    </body>
    </html>
    



    Friday, October 11, 2013 2:04 PM

Answers

  • User-417640953 posted

    Hi apicm,

    I’m glad to you post the issue to asp.net forum.

    According to your description and code you provided, I see that you are using asp.net control ASPNetVideo.

    From your code, I see that you want to change the VideoURL of RealPlayer dynamically.

    For this issue, I suggest you make sure your mp4 file url is correct. Please use the server.mapPath to handle your mp4 file path.

    <%@ Register Assembly="ASPNetVideo.NET4" Namespace="ASPNetVideo" TagPrefix="ASPNetVideo" %>
    <asp:DropDownList ID="DropDownList1" runat="server" Width="100px">
               <asp:ListItem Value="DHOOM-3.mp4" Text="Video1"></asp:ListItem>
               <asp:ListItem Value="Baatms.mp4" Text="Video2"></asp:ListItem>
           </asp:DropDownList>
            <asp:Button ID="Button1" runat="server" Text="Play" OnClick="Button1_Click" />
    <ASPNetVideo:WindowsMedia ID="WindowsMedia1" runat="server" Height="389px"  AutoPlay="false"  Width="465px">
                            <HTMLAlternativeTemplate>
                                 <h1>No!</h1>
                            </HTMLAlternativeTemplate>
    </ASPNetVideo:WindowsMedia>
    protected void Button1_Click(object sender, EventArgs e)
            {
                WindowsMedia1.VideoURL = Server.MapPath("~/videos/" + this.DropDownList1.SelectedValue);
                WindowsMedia1.AutoPlay = true;
                WindowsMedia1.LoopCount = 1;
            }
    

    Sorry for using c# and WindowsMedia. Thanks.

     

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 15, 2013 5:12 AM