Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-09
16
Medium Priority
?
523 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:GlobaLevel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
16 Comments
 
LVL 10

Author Comment

by:GlobaLevel
ID: 35086247
help any?
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35210745
Can you show us the browser "View Source" that that creates?
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 35244946
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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 10

Author Comment

by:GlobaLevel
ID: 35244953
Here is the "View Source".....
respond-to-user-w-mp3.txt
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 35244965
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
 
LVL 10

Author Comment

by:GlobaLevel
ID: 35245017
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
 
LVL 10

Author Comment

by:GlobaLevel
ID: 35245022
also..included...the project...its the test_web_monk.asp...that is the correct page...
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35245109
That looks beyond me.  If you put up the correct URL, does the file play or download as you want?
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 35245211
Thanks for the fast response..'no' it's not downloading or playing...
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35245420
Ok, a simpler way.  If you put the files on your computer, do they play there?  Just asking.
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 35262018
DaveBaldwin..I will have to try this approach...I was trying to pull from the server to the client...
0
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 35262949
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
 
LVL 10

Author Comment

by:GlobaLevel
ID: 35286062
DaveBaldwin,

Thanks for your help... resolved...
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35286855
You're welcome and thanks for the points.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

610 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