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:
Public Sub FillFields() If Not (rs.BOF And rs.EOF) Then txtDescription.Text = rs.Fields("Description") txtfilename.Text = rs.Fields("filename") End If End Sub
ADD NEW CODE:
VB Code:
Private Sub cmdAdd_Click() Dim bytData() As Byte Dim strDescription As String On Error GoTo err With dlgadd .Filter = "All Files (*.*|*.*" .DialogTitle = "Select File" .ShowOpen Open .FileName For Binary As #1 ReDim bytData(FileLen(.FileName)) If FileLen(.FileName) > "1000000" Then MsgBox "This is a large file it could take some time! Please be patient!!!", vbInformation, "Large File" End If End With Get #1, , bytData Close #1 Dim fn As String fn = dlgadd.FileName strDescription = InputBox("Enter description.", "New Picture") With rs DoEvents Me.MousePointer = 11 .AddNew .Fields("filename") = fn .Fields("Description") = strDescription .Fields("File").AppendChunk bytData .Update DoEvents End With Me.MousePointer = 0 FillFields Exit Sub err: If err.Number = 32755 Then Me.MousePointer = 0 Else Me.MousePointer = 0 MsgBox err.Description err.Clear End If End Sub
Now on cmdGet
Then on cmdPlayVB Code:
Private Sub cmdGet_Click() 'check for temporary file if it's found delete it temp = App.Path & "\" & txtfilename.Text If Len(Dir(temp)) > 0 Then Kill temp End If 'Open temp file file = FreeFile Open temp For Binary As #file 'Read temp file as binary into chunk 'this is the engine room ImgeSze = rs("FILE").ActualSize Do While offset < ImgeSze chunk() = rs("FILE").GetChunk(ChunkSize) Put #file, , chunk() offset = offset + ChunkSize Loop Close #file txtfile.Text = temp 'this is to load it's path name into the text box 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.VB Code:
Private Sub cmdPlay_Click() 'get filename mp1.FileName = txtfile.Text mp1.Play 'play it '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 Kill txtfile.Text 'kill it End Sub




Reply With Quote