ASP.net/API - user response pulls .mp3 from server to client....

based on how the client responds...the api will pull down different .mp3 from the server to the client that has windows media player installed...these mp3 are internal files...and belong to us..no copyright issues...

however it's not working...and Im not even sure..I am tying it to the media player correctly...

 
<System.Web.Services.WebMethod()> _
    Public Shared Function Sum(ByVal arg1 As String, ByVal arg2 As String) As Integer
        'On server side we can do anything, like we can access the Session.
        'We can do database access operation. Without postback.
        ' SOURCE : http://www.codeproject.com/KB/ajax/Ajax_Call_using_AjaxNet.aspx
       Try

          
            Dim dataReader As SqlDataReader
            Dim x As Integer = 0
            Dim sqlConnection As String
            Dim mp3_selection_file as string
 	    Dim mp3_selection_name as string
            
               
            Using sqlConn As New SqlConnection
                sqlConnection = "Data Source=xx.xx.xx.xx;Initial Catalog=dcdff;Trusted_connection=true;"
                sqlConn.ConnectionString = sqlConnection
                Dim SQLstring As String = "SELECT * FROM mp3_list WHERE TC_ID = '" & arg1 & "'" & _
   " AND campaign_name = '" & arg2 & "'"
          
                sqlConn.Open()
                Using command As New SqlCommand(SQLstring, sqlConn)
                    dataReader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
                    If dataReader.HasRows Then
                        Do While dataReader.Read()
                           mp3_selection = (dataReader("mp3_select").ToString())
			   session(session_mp3_file") = mp3_selection

 			    mp3_selection_name = (dataReader("mp3_select_name").ToString())
			   session(session_mp3_name") = mp3_selection
                        Loop
                        
                    End If
                    dataReader.Close()
                    sqlConn.Close()
                End Using
            End Using
            
            myArray.Sort()

            MyDropDown.DataSource = myArray
            MyDropDown.DataBind()
        Catch ex As Exception
           
        End Try

	label1.text = session(session_mp3_name")
	mediaPlayer.play = session(session_mp3_file")

       
       End Function

Open in new window

LVL 10
GlobaLevelProgrammerAsked:
Who is Participating?
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
I'm just trying to establish what works and so far that has been nothing.  I always try to work from simple things that work and then build from there.  If you don't know what works, it is very hard to make any progress.

If you can click on them on your computer and have them play, then you should be able to click on them thru a direct link on the website and have them play.  Then if that works you can go back to developing the methods you were working on with the confidence that the files will play when you access them correctly.
0
 
GlobaLevelProgrammerAuthor Commented:
help any?
0
 
Dave BaldwinFixer of ProblemsCommented:
Can you show us the browser "View Source" that that creates?
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
GlobaLevelProgrammerAuthor Commented:
DaveBaldwin,
I apologize for the late response as Ive been out of town...

here is the code behind below...


Imports System.Data.SqlClient
Imports System.IO
Imports System.Data.SqlClient.SqlDataAdapter
Imports System.Data.SqlClient.SqlConnection
Imports System.String
Imports System.StringComparison
Imports System.Text.StringBuilder
Imports System.Web.UI
Imports System.Web.UI.Page
Imports System.Web.UI.WebControls.TextBox
Imports System.Web.UI.WebControls
Imports System.Web.UI.ExtenderControl
Imports System.Random
Imports System.DateTime
Imports System.Data.OleDb
Imports System.Text
Imports System.Data.Odbc
Imports System.Data
Imports System.Text.RegularExpressions
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.Services
Imports System.Web.SessionState.HttpSessionState

Partial Class test2
    Inherits System.Web.UI.Page

    <System.Web.Services.WebMethod()> _
     Public Shared Function Sum(ByVal arg1 As String, ByVal arg2 As String) As String
        Try
            '-----------------------------------------------------------
            ' RETURN AN AUDIO PORTION OF MP3..FOR VISUALLY IMPAIRED....

            Send_Audio_Response(arg1)


            '-----------------------------------------------------------
            ' RETURN A WRITTEN PORTION OF MP3..FOR HEARING IMPAIRED....

            Dim total_total_func As String
            Dim total_func As String

            total_func = arg1 * arg2
            total_total_func = Sum1(total_func)


            Return total_total_func
            ' ----------------------------------------------
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Shared Function Sum1(ByVal arg1 As String) As String
        Try
            Dim total_func As String
            total_func = "C:/file/" & arg1 & ".mp3"

            Return total_func
        Catch ex As Exception
            Throw ex
        End Try
    End Function


    Public Shared Function Send_Audio_Response(ByVal arg1 As String) As Object

        ' ----------------------------
        ' DECIDE WHICH FILE AND SEND..
        ' --------------------------
        Dim mp3Path As Object

        mp3Path = Find_Audio_Response(arg1)

        Dim fs As FileStream = New FileStream(mp3Path, FileMode.Open, FileAccess.Read, FileShare.Read)
        Dim br As New BinaryReader(fs)
        Dim bytes As Byte() = br.ReadBytes(CInt(fs.Length))

        Send_Audio_Response.Response.Clear()
        Send_Audio_Response.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", System.IO.Path.GetFileName(mp3Path)))
        Send_Audio_Response.Response.ContentType = "audio/mpeg"
        Send_Audio_Response.Response.BinaryWrite(bytes)
        Send_Audio_Response.Response.Flush()

        br.Close()
        fs.Close()

        Return True

    End Function

    Public Shared Function Find_Audio_Response(ByVal mp3_criteria As String) As Object

        ' ----------------------------
        ' DECIDE WHICH FILE AND SEND..
        ' --------------------------

        Try
            Dim MyDropDown As DropDownList

            Dim myArray As New ArrayList()
            Dim dataReader As SqlDataReader
            Dim x As Integer = 0
            Dim sqlConnection As String
            Dim tc_id As String
            Dim mp3_path As String
            tc_id = ""

            Using sqlConn As New SqlConnection
                sqlConnection = "Data Source=xx.xx.xx.xx;Initial Catalog=Terrrnert;Trusted_connection=true;"
                sqlConn.ConnectionString = sqlConnection
                Dim SQLstring As String = "SELECT distinct(mp3_path) FROM campaign WHERE TC_ID = '" & tc_id & "' WHERE TC_ID = '" & mp3_criteria & "'"

                sqlConn.Open()
                Using command As New SqlCommand(SQLstring, sqlConn)
                    dataReader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
                    If dataReader.HasRows Then
                        Do While dataReader.Read()
                            mp3_path = dataReader("mp3_path").ToString()
                            Find_Audio_Response.session("Find_mp3_file") = mp3_path
                        Loop

                    End If
                    dataReader.Close()
                    sqlConn.Close()
                End Using
            End Using




        Catch ex As Exception

        End Try

        Return Find_Audio_Response.session("Find_mp3_file")


    End Function



End Class

Open in new window

0
 
GlobaLevelProgrammerAuthor Commented:
Here is the "View Source".....
respond-to-user-w-mp3.txt
0
 
GlobaLevelProgrammerAuthor Commented:
Here is the client side code...
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test_web_monk.aspx.vb" Inherits="test2" %>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <script src="http://code.jquery.com/jquery-1.5.min.js" language="javascript" type="text/javascript"></script> 

    <script language="javascript" type="text/javascript">
<!--
    var touched = false;
    var timer = null;
    var timeout = 4000; // 4 seconds

var timer;

function startSearchTime(e) {
    window.clearTimeout(timer);
    var unicode = e.keyCode ? e.keyCode : e.charCode

    var timeToWait = 2000; // time in milliseconds;
    timer = window.setTimeout("doSearch()", timeToWait);
}

function doSearch() {
    window.clearTimeout(timer);
   // document.getElementById("Button1").click();
    CallSum()
}



    function CallSum() {
        var txt1 = $get("<%= hotarea.ClientID %>");
        var txt2 = $get("<%= txt2.ClientID %>");
        var txtresult = $get("txtSum");
        PageMethods.Sum(txt1.value, txt2.value, OnCallSumComplete, OnCallSumError,txtresult);
    }

    function OnCallSumComplete(result, txtresult, methodName) {
       //Show the result in txtresult
		txtresult.value = result;
    }

    function OnCallSumError(error, userContext, methodName) {
        if (error !== null) {
            alert(error.get_message());
        }
    }

    function $get(id) {
        return document.getElementById(id);
    }

// -->
</script>
    <style type="text/css">
        #TextArea1
        {
            width: 425px;
            height: 234px;
        }
        #hotarea
        {
            height: 192px;
            width: 424px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <br />
        txt2</div>
    <asp:TextBox ID="txt2" runat="server">6</asp:TextBox>
    <p>
        txtsum</p>
    <asp:TextBox ID="txtsum" runat="server"></asp:TextBox>
    <p>
        &nbsp;</p>
    <p>
        hotarea</p>
    <p>
        <asp:TextBox ID="hotarea" runat="server" Height="215px" Width="398px" onkeyup="startSearchTime(event);"></asp:TextBox>
    </p>
    <p>
        &nbsp;</p>
    <p>
        &nbsp;</p>
        <asp:scriptmanager ID="Scriptmanager1" runat="server" EnablePageMethods="true"></asp:scriptmanager>
    </form>
</body>
</html>

Open in new window

0
 
GlobaLevelProgrammerAuthor Commented:
so the users inputs a number...in the hotarea...it is multiplied by txt2...to produce a value...

then the SUm1 function creates the path of the mp3 based on value of the multiplication(yet to be added)

then I need to tie in the Send_audio_response to select the correct mp3 to download to the client...
zzz-WebSite88-zip.zip
0
 
GlobaLevelProgrammerAuthor Commented:
also..included...the project...its the test_web_monk.asp...that is the correct page...
0
 
Dave BaldwinFixer of ProblemsCommented:
That looks beyond me.  If you put up the correct URL, does the file play or download as you want?
0
 
GlobaLevelProgrammerAuthor Commented:
Thanks for the fast response..'no' it's not downloading or playing...
0
 
Dave BaldwinFixer of ProblemsCommented:
Ok, a simpler way.  If you put the files on your computer, do they play there?  Just asking.
0
 
GlobaLevelProgrammerAuthor Commented:
DaveBaldwin..I will have to try this approach...I was trying to pull from the server to the client...
0
 
GlobaLevelProgrammerAuthor Commented:
DaveBaldwin,

Thanks for your help... resolved...
0
 
Dave BaldwinFixer of ProblemsCommented:
You're welcome and thanks for the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.