Wav Files

  • Dear All

    I want to store the wav file in sql db. I was successful in storing the same thro adodb.stream object. I want to know how to retrive the stored wav file and play it.

    When i tried the mediaplayer gives me an error msg saying "Invalid File Format"

    Can any body help me.

    Thnks in advance

    Suresh

    suresh


    suresh

  • How are you retrieving it? Through a web interface? If so, are you setting the HTTP headers properly?

    K. Brian Kelley

    bkelley@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/bkelley/

    K. Brian Kelley
    @kbriankelley

  • Hai Brian Kelley

    It is not a web based application. I have a binary data type in my sql. I got a client in vb where i get the wave file from the user.I save the wave file in binary format using adodb.stream object.

    Hope i am right in my process. If not yr comment pls......

    When i try to retive the wave file in mediaplayer,

    thro stream object based on a pk field

    i get an error "Invalid file format"

    suresh


    suresh

  • Can you post the code? No reason the file you retrieved shouldnt be exactly what it was when you stored it.

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

  • Andy Warren

    I am pasting the code below.

    My objective is that what ever wav file selected by the user should be stored in db. When i retrive a wav file based on pk_field, the retrived wav file

    must be written to a local file for eg. Bell.Wav

    I hope my code is correct. If not pls comment

    where i have gone wrong.

    Thanks in advance

    Dim Cnn As ADODB.Connection

    Dim Rst As ADODB.Recordset

    Dim mStream As ADODB.Stream

    Dim szStr As String

    Private Sub cmbNo_Click()

    On Error Resume Next

    Set Rst = New ADODB.Recordset

    Set mStream = New ADODB.Stream

    mStream.Type = adTypeBinary

    mStream.Open

    szStr = "Select * from Test1 Where Col1 = " & Val(cmbNo.Text)

    Rst.Open szStr, Cnn, adOpenStatic, adLockReadOnly

    If Not Rst.EOF Then

    mStream.Write Rst("Sounds")

    mStream.SaveToFile App.Path & "\Bell.wav", adSaveCreateOverWrite

    MediaPlayer1.Open App.Path & "\Bell.wav" ' Gives me an error saying Invalid File Format

    End If

    End Sub

    Private Sub cmdBrowse_Click()

    CommonDialog1.Filter = "Audio (*.wav)|*.wav"

    CommonDialog1.ShowOpen

    txtFile.Enabled = False

    txtFile = CommonDialog1.FileName

    End Sub

    Private Sub cmdClose_Click()

    Unload Me

    End Sub

    Private Sub cmdSave_Click()

    On Error Resume Next

    Set Rst = New ADODB.Recordset

    Set mStream = New ADODB.Stream

    mStream.Type = adTypeBinary

    mStream.Open

    szStr = "Select * from Test1 Where Col1 = " & Val(cmbNo.Text)

    Rst.Open szStr, Cnn, adOpenKeyset, adLockOptimistic

    If Rst.EOF Then

    Rst.AddNew

    Rst("Col1") = Val(cmbNo.Text)

    mStream.LoadFromFile txtFile

    Rst("Sounds") = mStream.Read

    Else

    Rst("Col1") = Val(cmbNo.Text)

    mStream.LoadFromFile txtFile 'App.Path & "\Click1.wav"

    Rst("Sounds") = mStream.Read

    End If

    Rst.Update

    Rst.Close

    mStream.Close

    End Sub

    Private Sub Form_Load()

    On Error Resume Next

    Dim szMachine As String

    Dim szDb As String

    Dim iLoop As Integer

    szMachine = "Sw4"

    szDb = "Pubs"

    For iLoop = 1 To 255

    cmbNo.AddItem iLoop

    Next iLoop

    Set Cnn = New ADODB.Connection

    Cnn.ConnectionString = "Provider=sqloledb;Data Source=" & szMachine & ";Initial Catalog= " & szDb & ";User Id=sa;Password=;"

    Cnn.Open

    End Sub

    Private Sub Form_Unload(Cancel As Integer)

    Set frmAlarm = Nothing

    Unload Me

    End Sub

    suresh


    suresh

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply