Wanna play music from the db!

This is a simple demo.
Add the media player control(mp1), a text box(txtfile) and another 2 command buttons(cmdGet and cmdPlay) to the above code etc.

IMPORTANT: you gotta add a field called filename and a text box called txtfilename as well. The make changes to cmdadd and fillfields subs.

I done it for ya coz i'm so noice!
VB Code:
  1. Public Sub FillFields()
  2.     If Not (rs.BOF And rs.EOF) Then
  3.         txtDescription.Text = rs.Fields("Description")
  4.         txtfilename.Text = rs.Fields("filename")
  5.     End If
  6. End Sub

ADD NEW CODE:

VB Code:
  1. Private Sub cmdAdd_Click()
  2.     Dim bytData() As Byte
  3.     Dim strDescription As String
  4.     On Error GoTo err
  5.    
  6.     With dlgadd
  7.        
  8.         .Filter = "All Files (*.*|*.*"
  9.         .DialogTitle = "Select File"
  10.         .ShowOpen
  11.  
  12.        
  13.         Open .FileName For Binary As #1
  14.         ReDim bytData(FileLen(.FileName))
  15.         If FileLen(.FileName) > "1000000" Then
  16.         MsgBox "This is a large file it could take some time! Please be patient!!!", vbInformation, "Large File"
  17.         End If
  18.     End With
  19.    
  20.     Get #1, , bytData
  21.     Close #1
  22.    
  23.     Dim fn As String
  24.     fn = dlgadd.FileName
  25.     strDescription = InputBox("Enter description.", "New Picture")
  26.    
  27.     With rs
  28.     DoEvents
  29.     Me.MousePointer = 11
  30.         .AddNew
  31.         .Fields("filename") = fn
  32.         .Fields("Description") = strDescription
  33.         .Fields("File").AppendChunk bytData
  34.         .Update
  35.     DoEvents
  36.     End With
  37.     Me.MousePointer = 0
  38.     FillFields
  39.     Exit Sub
  40. err:
  41.     If err.Number = 32755 Then
  42.         Me.MousePointer = 0
  43.     Else
  44.     Me.MousePointer = 0
  45.         MsgBox err.Description
  46.         err.Clear
  47.     End If
  48. End Sub

Now on cmdGet

VB Code:
  1. Private Sub cmdGet_Click()
  2.  
  3.             'check for temporary file if it's found delete it
  4.             temp = App.Path & "\" & txtfilename.Text
  5.             If Len(Dir(temp)) > 0 Then
  6.                 Kill temp
  7.             End If
  8.  
  9.             'Open temp file
  10.             file = FreeFile
  11.             Open temp For Binary As #file
  12.  
  13.             'Read temp file as binary into chunk
  14.             'this is the engine room
  15.             ImgeSze = rs("FILE").ActualSize
  16.             Do While offset < ImgeSze
  17.                chunk() = rs("FILE").GetChunk(ChunkSize)
  18.                Put #file, , chunk()
  19.                offset = offset + ChunkSize
  20.             Loop
  21.  
  22.             Close #file
  23. txtfile.Text = temp
  24. 'this is to load it's path name into the text box
  25. End Sub
Then on cmdPlay
VB Code:
  1. Private Sub cmdPlay_Click()
  2. 'get filename
  3. mp1.FileName = txtfile.Text
  4. mp1.Play 'play it
  5. 'Please modify the below line so when it's finished playing it, it 'deletes the file it made! At the moment it'll work but you'll get an error
  6. Kill txtfile.Text 'kill it
  7. End Sub
It just uses the temp file we make when retrieving the file out of the database and plays it then deletes it when finished playing.