asp.net query ms sql queue, download .wav audio file with windows media...

GlobaLevel
GlobaLevel used Ask the Experts™
on
I am running into errors in my code where its suppose to query a ms sql table, if any records(file Paths), then pass on as a varaible where the client can download and listen once the page opens...right now the files are on a file server....too many .wav to make an .aspx for each..see code below...
<%@ Page language="vb.net" %>


<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Configuration" %>




<script language="vb.net" runat="server">

public sub Page_Load(Object sender, EventArgs e)


dim latest_wav as object


  ' -=-=-=-
  ' query ms sql server for next file to be downloaded
  ' -=-=-=-
  SqlConnection myConnection
  SqlCommand myCommand
  SqlDataReader myDataReader
  
  myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"])
  myConnection.Open()

  'prepare sql statements
  myCommand = new SqlCommand("SELECT TOP 1 * FROM Queue", myConnection)
  myDataReader = myCommand.ExecuteReader()
 
  ' for countiunous query.....
  For i = 1 to 500



  
  while (myDataReader.Read())

   
  myDataReader["latest_wav"])
  

  ' once the next file path is found download...
   DirectoryInfo di = new DirectoryInfo(latest_wav)
   FileInfo[] rgFiles = di.GetFiles("*.aspx");
   foreach(FileInfo fi in rgFiles)
 
 Response.Write("<br><a href=" + fi.Name + ">" + fi.Name + "</a>")

 ' wait for the file to complete download and playing for next query....
 application.sleep(3000)

Next 

 'cleanup objects
 myDataReader.Close()
 myConnection.Close()


 ' pocket IE
 ' http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_24406793.html?sfQueryTermInfo=1+10+30+asp.net+download+wav

End Sub




</script>
<html>
<head>
<title>Player Page</title>
</head>
<body>
This is the media url: <asp:label id="srcurl" runat="server" />
<br />
<hr />

<!-- START PLAYER AUDIO/VIDEO WINDOW -->

        <EMBED 
            name="player" 
        id="player" 
        TYPE="application/x-mplayer2" 
           ' document.getElementById("player").src = 'http://www.blah.com/myvideo.asx;'
            NAME="MediaPlayer" 
            WIDTH="320" 
            HEIGHT="240">
        </EMBED>
          <NOEMBED>
          <FONT FACE="Verdana" SIZE="1" COLOR="#000000">You need to have Windows Media Player in order to view this performance. Download it from <A href="http://www.windowsmedia.com/" TARGET="_blank">http://www.windowsmedia.com/</A></FONT>
          </NOEMBED>

<!-- END PLAYER AUDIO/VIDEO WINDOW -->

</body>
</html>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
GlobaLevelProgrammer

Author

Commented:
help?
Most Valuable Expert 2012
Top Expert 2008
Commented:
I don't really see a question in there...are you looking for help with errors?  What are the errors?
GlobaLevelProgrammer

Author

Commented:
really appreciate your help...so heres what is going on...basically its a survey to test how well the user knows their 80 songs..

on page_load songs snippets will be begin playing about 10 seconds long..one after another...in that time the user needs to enter which 80's band
 ..they think it is...before the next song plays..then another snippet plays and they enter the name of the and for that
..their answer will upload to a ms sql db...PLEASE note..
it cant be stored at the end of the session to be sent to sql as a bulk..
..it has to be sent whenever the loop calls it to send...pretty much immediately...

basically repeat this  over and over...
here is the code I have below..its rough...with alot of errors : )
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="GlobalLevel_20101022.aspx.vb" Inherits="Global022" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Imports = " System.Data.SqlClient" %>
<%@ Imports = " System.IO "%>



<script runat="server">



Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim strUnderwriter As String
    strUnderwriter = Request.QueryString("u")
    
    Dim strURL As String
    strURL = Request.QueryString("v")
    
    Dim strUTitle As String
    strUTitle = Request.QueryString("ut")
    
    Dim strVTitle As String
    strVTitle = Request.QueryString("vt")
    
' loop continuously to find new.wav files on the sql back end...then play as they enter the player...on client
' the .wav files are at most 20 seconds long per .wav
' so  play over and over...as they enter the client

For i = 1 to 1000

        Response.ContentType = "video/x-ms-asf"
        Response.Expires = 0
' query to get wav snippets from sql 
 gvWaveFiles_RowCommand()

    Response.Write("<ASX version=""3.0"">")
    Response.Write("<ENTRY CLIENTSKIP=""NO"">")
    Response.Write("<TITLE>" & (strUTitle) & "</TITLE>")
    Response.Write("<COPYRIGHT> 2008 </COPYRIGHT>")
    Response.Write("<ref href = """ & (strUnderwriter) & """ />")
    Response.Write("</ENTRY>")
    Response.Write("<ENTRY>")
    Response.Write("<TITLE>" & (strVTitle) & "</TITLE>")
    Response.Write("<ref href =""" & (strURL) & """ />")
    Response.Write("<COPYRIGHT> 2008 </COPYRIGHT>")
    Response.Write("</ENTRY>")
    Response.Write("</ASX>")
    
    send_reponse_to_server()
    
    

next

' source:http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23707335.html?sfQueryTermInfo=1+10+30+asp.net+playlist

Partial Class grab_wav_files
    Inherits System.Web.UI.Page



    Protected Sub gvWaveFiles_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvWaveFiles.RowCommand
       
            Dim waveId As Integer = gvWaveFiles.DataKeys(e.CommandArgument).Value
            Dim sqlPlayWaveFile As New SqlDataAdapter("SELECT [WaveFileData] FROM [tblWaveFiles] WHERE ([ID] = @ID)", _conn)
            sqlPlayWaveFile.SelectCommand.Parameters.AddWithValue("@ID", waveId)
            Try
                If Not _conn.State = Data.ConnectionState.Open Then
                    _conn.Open()
                End If
                Dim WaveFile As Byte() = sqlPlayWaveFile.SelectCommand.ExecuteScalar()
                Dim strFile As FileStream = File.OpenWrite(Server.MapPath("~/stream.wav"))
                Dim str As New MemoryStream()
                str.Write(WaveFile, 0, WaveFile.Length)
                str.WriteTo(strFile)
                strFile.Flush()
                strFile.Close()
                Response.ContentType = "audio/x-wav"
                Response.Redirect("~/stream.wav")
            Catch ex As Exception
                'TODO: Implement error handling logic.
            Finally
                If Not _conn.State = Data.ConnectionState.Closed Then
                    _conn.Close()
                End If
            End Try
   
    End Sub



public sub send_reponse_to_server( ByVal sender As Object, ByVal e as events)

  dim user_guess as string

  user_guess = textbox_user_guess.text

   Dim waveId As Integer = gvWaveFiles.DataKeys(e.CommandArgument).Value
            Dim sqlPlayWaveFile As New SqlDataAdapter("UPDATE [user_guess] FROM [user_guess_80_band] WHERE ([ID] = @ID)", _conn)
            sqlPlayWaveFile.SelectCommand.Parameters.AddWithValue("@ID", waveId)
            Try
                If Not _conn.State = Data.ConnectionState.Open Then
                    _conn.Open()
                End If
                Dim WaveFile As Byte() = sqlPlayWaveFile.SelectCommand.ExecuteScalar()
                Dim strFile As FileStream = File.OpenWrite(Server.MapPath("~/stream.wav"))
                Dim str As New MemoryStream()
                str.Write(WaveFile, 0, WaveFile.Length)
                str.WriteTo(strFile)
                strFile.Flush()
                strFile.Close()
                Response.ContentType = "audio/x-wav"
                Response.Redirect("~/stream.wav")
            Catch ex As Exception
                'TODO: Implement error handling logic.
            Finally
                If Not _conn.State = Data.ConnectionState.Closed Then
                    _conn.Close()
                End If
            End Try


end class

</script>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="guess_result" text="Guess the name of the band of the 80 songs that are playing in rapid session, enter your guess below..you only have a few seconds before the next one begins..so be quick!!"runat="server"></asp:Label>
        <br />
        <asp:textbox="textbox_user_guess" runat="server" />&nbsp;&nbsp;
        
        <br />
        
        <br />
        <br />
        Guess the song snippet:<br />
    </div>
    <div>
        <object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" id="VIDEO" type="video/x-ms-asf"
	            width="400" height="365" standby="Loading Microsoft Windows Media Player components..."
	            codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715">
	            <param name="StretchToFit" value="1" />
	            <param name="AutoStart" value="true" />
	            <param name="Balance" value="0" />
	            <param name="EnableContextMenu" value="1" />
	            <param name="Enabled" value="1" />
	            <param name="EnableErrorDialogs" value="1" />
	            <param name="WindowlessVideo" value="0" />
	            <param name="Rate" value="1.000" />
	            <param name="CurrentPosition" value="0.000" />
	            <param name="CurrentMarker" value="1" />
	            <param name="FullScreen" value="0" />
	            <param name="Mute" value="0" />
	            <param name="PlayCount" value="1" />
	            <param name="Uimode" value="Full" />
	            <param name="Volume" value="50" />
	            <param name="URL"  value ="<%Response.Write(strPlay) %> "/>
	            <embed id="mpFAB" type="video/x-ms-asf" src="<%Response.Write(strPlay) %>" width="400" height="345"
	                showcontrols="1" />
	          
	            
	  </object>


    </div>
    </form>
</body>
</html>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial