Newsgroup: it.comp.appl.access
Titolo: Play&Record sound

Ciao.
Vorrei poter registrare dei file audio wav o mp3 (pochi secondi)
all'interno di
un db di access. Come posso fare?
Esiste qualcosa tipo OCX etc.... che mi permetta di fare questo?
Roberto

 wrote in message 39C270DB...@tin.it...

Per riprodurre files con estensioni wav- mid- avi copia, in un modulo, il
seguente codice:
Option Compare Database
Option Explicit
Public Const pcsSYNC = 0      ' aspetta sino al termine del brano
Public Const pcsASYNC = 1     ' non aspetta il termine del brano
Public Const pcsNODEFAULT = 2 ' se il brano non esiste, non avviare quello
di default
Public Const pcsLOOP = 8      ' suona loop infinito
Public Const pcsNOSTOP = 16   ' non interrompe un brano
'Sound APIs
Private Declare Function apiPlaySound Lib "Winmm.dll" Alias "sndPlaySoundA"
_
    (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
'AVI APIs
Private Declare Function apimciSendString Lib "Winmm.dll" Alias
"mciSendStringA" _
    (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
    ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Declare Function apimciGetErrorString Lib "Winmm.dll" _
    Alias "mciGetErrorStringA" (ByVal dwError As Long, _
    ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
Function fPlayStuff(ByVal strFilename As String, _
            Optional intPlayMode As Integer) As Long
'Fornire un Nomefile con estensione
'Supporta file di tipo Wav, AVI, MID
Dim lngRet As Long
Dim strTemp As String
    Select Case LCase(fGetFileExt(strFilename))
        Case "wav":
            If Not IsMissing(intPlayMode) Then
                lngRet = apiPlaySound(strFilename, intPlayMode)
            Else
                MsgBox "Specificare play mode."
                Exit Function
            End If
        Case "avi", "mid":
            strTemp = String$(256, 0)
            lngRet = apimciSendString("play " & strFilename, strTemp, 255,
0)
    End Select
    fPlayStuff = lngRet
End Function
Function fStopStuff(ByVal strFilename As String)
'Stop il multimedia playback
Dim lngRet As Long
Dim strTemp As String
    Select Case LCase(fGetFileExt(strFilename))
        Case "Wav":
            lngRet = apiPlaySound(0, pcsASYNC)
        Case "avi", "mid":
            strTemp = String$(256, 0)
            lngRet = apimciSendString("stop " & strFilename, strTemp, 255,
0)
    End Select
    fStopStuff = lngRet
End Function
Private Function fGetFileExt(ByVal strFullPath As String) As String
Dim intPos As Integer, intLen As Integer
    intLen = Len(strFullPath)
    If intLen Then
        For intPos = intLen To 1 Step -1
            'Trova l'ultimo \
            If Mid$(strFullPath, intPos, 1) = "." Then
                fGetFileExt = Mid$(strFullPath, intPos + 1)
                Exit Function
            End If
        Next intPos
    End If
End Function
Function fGetError(ByVal lngErrNum As Long) As String
    ' Trasforma il codice errore in stringa
    Dim lngx As Long
    Dim strErr As String
    strErr = String$(256, 0)
    lngx = apimciGetErrorString(lngErrNum, strErr, 255)
    strErr = Left$(strErr, Len(strErr) - 1)
    fGetError = strErr
End Function
Function fatest()
Dim a As Long
    a = fPlayStuff("C:\winnt\clock.avi")
    'a = fStopStuff("C:\winnt\clock.avi")
End Function
Per un utilizzo si puň richiamare, es. evento Caricamento di una Form, cosě
:
Private Sub Form_Load()
   fPlayStuff ("c:\mid\dance.mid")
End Sub





