My program encodes and mp3 and then deletes the source wave file.
When i run my program in the vb6 ide it works properly, but when i compile it and run it after it encodes adngets up to the deleting bit i get an error "Runtime Error 1000-path/file access error". Does ne1 no what this means and how i can fix it?
here is the mp3 encoding code
Function MP3ENC(file As String)
' Now.. This one is going to be little bit complicated....
On Error GoTo ErrHandler
'On Error Resume Next
ChDrive App.Path
ChDir App.Path
' Check that file exists...
If Dir(file) = "" Then
MsgBox "File not found...", vbCritical, "Critical Error"
Exit Function
End If
Cancelled = False
' Command3.Visible = True
' Fill beConfig structure....
Dim beConfig As PBE_CONFIG
beConfig.dwConfig = BE_CONFIG_LAME
With beConfig.format.LHV1
'// this are the default settings for testcase.wav
.dwStructVersion = 1
.dwStructSize = Len(beConfig)
.dwSampleRate = 44100 '// INPUT FREQUENCY
.dwReSampleRate = 0 '// DON"T RESAMPLE
.nMode = BE_MP3_MODE_JSTEREO '// OUTPUT IN STREO
' .dwBitrate = 128 '// MINIMUM BIT RATE
' .nPreset = LQP_HIGH_QUALITY '// QUALITY PRESET SETTING
.dwMpegVersion = MPEG1 '// MPEG VERSION (I or II)
.dwPsyModel = 0 '// USE DEFAULT PSYCHOACOUSTIC MODEL
.dwEmphasis = 0 '// NO EMPHASIS TURNED ON
' .bOriginal = False '// SET ORIGINAL FLAG
.bNoRes = True '// No Bit resorvoir
.dwBitrate = modGlobal.Bitrate
.bCRC = modGlobal.CRC
.bCopyright = modGlobal.Copy
.bOriginal = modGlobal.Orig
.bPrivate = modGlobal.Priv
End With
Dim Error As Long
Dim dwSamples As Long, dwMP3Buffer As Long, hbeStream As Long
' Init MP3 Stream
Error = beInitStream(VarPtr(beConfig), VarPtr(dwSamples), VarPtr(dwMP3Buffer), VarPtr(hbeStream))
'// Check result
If Error <> BE_ERR_SUCCESSFUL Then
Err.Raise Error, "Lame", GetErrorString(Error)
End If
' Open Files...
Dim toRead As Long, toWrite As Long
Dim Done As Long
Dim Length As Long
Length = FileLen(file)
Dim ReadFile As clsFileIo
Set ReadFile = New clsFileIo
ReadFile.OpenFile (file)
Dim WriteFile As clsFileIo
Set WriteFile = New clsFileIo
WriteFile.OpenFile Left(file, (Len(file) - 4)) & ".mp3" 'filemp3
' Allocate memory for buffers...
Dim WavPtr1 As Long
Dim WavPtr2 As Long
Dim MP3Ptr1 As Long
Dim MP3Ptr2 As Long
WavPtr1 = GlobalAlloc(&H40, dwSamples * 2)
WavPtr2 = GlobalLock(WavPtr1)
MP3Ptr1 = GlobalAlloc(&H40, dwMP3Buffer)
MP3Ptr2 = GlobalLock(MP3Ptr1)
'Skip WAV header
Dim temp(1 To 44) As Byte
Call ReadFile.ReadBytes(VarPtr(temp(1)), 44)
' And here we go....
Do While Done < Length
'//set up how much to readinto the buffer
If Done + dwSamples * 2 < Length Then
toRead = dwSamples * 2
Else
toRead = Length - Done
End If
' Read into buffer
Call ReadFile.ReadBytes(WavPtr2, toRead)
Done = Done + toRead
toRead = toRead / 2
' Encode buffer
Error = beEncodeChunk(hbeStream, toRead, WavPtr2, MP3Ptr2, VarPtr(toWrite))
' Check result...
If Error <> BE_ERR_SUCCESSFUL Then
Call beCloseStream(hbeStream)
Err.Raise Error, "Lame", GetErrorString(Error)
End If
' Write Buffer...
If toWrite > 0 Then
Call WriteFile.WriteBytes(MP3Ptr2, toWrite)
End If
' Report status to user....
ChangeProgress "Encoding: " & Left(file, (Len(file) - 4)) & ".mp3", "Encoding", CSng(Done), CSng(Length)
If Cancelled = True Then Exit Do
DoEvents
Loop
' Deinitialize stream and write last bytes to MP3
Error = beDeinitStream(hbeStream, MP3Ptr2, VarPtr(toWrite))
If toWrite > 0 Then
WriteFile.WriteBytes MP3Ptr2, toWrite
End If
' Clear buffers....
GlobalFree MP3Ptr2
GlobalFree WavPtr2
' Close files
Call WriteFile.CloseFile
Call ReadFile.CloseFile
Set WriteFile = Nothing
Set ReadFile = Nothing
' Close stream
Call beCloseStream(hbeStream)
' Command3.Visible = False
' WriteVBRHeader (if we use variable bitrate...)
'Call beWriteVBRHeader(ChangeExt(Text1, "mp3"))
If modGlobal.DelWave = True Then
Kill file
End If
Exit Function
ErrHandler:
' Damn.. Something went wrong and this one should tell what...
' At time of debugin.. This one was place where code ended all the time...
' But now it should never come into this point....
MsgBox Err.Description, vbCritical, "Critical error..."
If WavPtr2 Then GlobalFree WavPtr2
If MP3Ptr2 Then GlobalFree MP3Ptr2
WriteFile.CloseFile
ReadFile.CloseFile
Set WriteFile = Nothing
Set ReadFile = Nothing
Exit Function
End Function
When i run my program in the vb6 ide it works properly, but when i compile it and run it after it encodes adngets up to the deleting bit i get an error "Runtime Error 1000-path/file access error". Does ne1 no what this means and how i can fix it?
here is the mp3 encoding code
Function MP3ENC(file As String)
' Now.. This one is going to be little bit complicated....
On Error GoTo ErrHandler
'On Error Resume Next
ChDrive App.Path
ChDir App.Path
' Check that file exists...
If Dir(file) = "" Then
MsgBox "File not found...", vbCritical, "Critical Error"
Exit Function
End If
Cancelled = False
' Command3.Visible = True
' Fill beConfig structure....
Dim beConfig As PBE_CONFIG
beConfig.dwConfig = BE_CONFIG_LAME
With beConfig.format.LHV1
'// this are the default settings for testcase.wav
.dwStructVersion = 1
.dwStructSize = Len(beConfig)
.dwSampleRate = 44100 '// INPUT FREQUENCY
.dwReSampleRate = 0 '// DON"T RESAMPLE
.nMode = BE_MP3_MODE_JSTEREO '// OUTPUT IN STREO
' .dwBitrate = 128 '// MINIMUM BIT RATE
' .nPreset = LQP_HIGH_QUALITY '// QUALITY PRESET SETTING
.dwMpegVersion = MPEG1 '// MPEG VERSION (I or II)
.dwPsyModel = 0 '// USE DEFAULT PSYCHOACOUSTIC MODEL
.dwEmphasis = 0 '// NO EMPHASIS TURNED ON
' .bOriginal = False '// SET ORIGINAL FLAG
.bNoRes = True '// No Bit resorvoir
.dwBitrate = modGlobal.Bitrate
.bCRC = modGlobal.CRC
.bCopyright = modGlobal.Copy
.bOriginal = modGlobal.Orig
.bPrivate = modGlobal.Priv
End With
Dim Error As Long
Dim dwSamples As Long, dwMP3Buffer As Long, hbeStream As Long
' Init MP3 Stream
Error = beInitStream(VarPtr(beConfig), VarPtr(dwSamples), VarPtr(dwMP3Buffer), VarPtr(hbeStream))
'// Check result
If Error <> BE_ERR_SUCCESSFUL Then
Err.Raise Error, "Lame", GetErrorString(Error)
End If
' Open Files...
Dim toRead As Long, toWrite As Long
Dim Done As Long
Dim Length As Long
Length = FileLen(file)
Dim ReadFile As clsFileIo
Set ReadFile = New clsFileIo
ReadFile.OpenFile (file)
Dim WriteFile As clsFileIo
Set WriteFile = New clsFileIo
WriteFile.OpenFile Left(file, (Len(file) - 4)) & ".mp3" 'filemp3
' Allocate memory for buffers...
Dim WavPtr1 As Long
Dim WavPtr2 As Long
Dim MP3Ptr1 As Long
Dim MP3Ptr2 As Long
WavPtr1 = GlobalAlloc(&H40, dwSamples * 2)
WavPtr2 = GlobalLock(WavPtr1)
MP3Ptr1 = GlobalAlloc(&H40, dwMP3Buffer)
MP3Ptr2 = GlobalLock(MP3Ptr1)
'Skip WAV header
Dim temp(1 To 44) As Byte
Call ReadFile.ReadBytes(VarPtr(temp(1)), 44)
' And here we go....
Do While Done < Length
'//set up how much to readinto the buffer
If Done + dwSamples * 2 < Length Then
toRead = dwSamples * 2
Else
toRead = Length - Done
End If
' Read into buffer
Call ReadFile.ReadBytes(WavPtr2, toRead)
Done = Done + toRead
toRead = toRead / 2
' Encode buffer
Error = beEncodeChunk(hbeStream, toRead, WavPtr2, MP3Ptr2, VarPtr(toWrite))
' Check result...
If Error <> BE_ERR_SUCCESSFUL Then
Call beCloseStream(hbeStream)
Err.Raise Error, "Lame", GetErrorString(Error)
End If
' Write Buffer...
If toWrite > 0 Then
Call WriteFile.WriteBytes(MP3Ptr2, toWrite)
End If
' Report status to user....
ChangeProgress "Encoding: " & Left(file, (Len(file) - 4)) & ".mp3", "Encoding", CSng(Done), CSng(Length)
If Cancelled = True Then Exit Do
DoEvents
Loop
' Deinitialize stream and write last bytes to MP3
Error = beDeinitStream(hbeStream, MP3Ptr2, VarPtr(toWrite))
If toWrite > 0 Then
WriteFile.WriteBytes MP3Ptr2, toWrite
End If
' Clear buffers....
GlobalFree MP3Ptr2
GlobalFree WavPtr2
' Close files
Call WriteFile.CloseFile
Call ReadFile.CloseFile
Set WriteFile = Nothing
Set ReadFile = Nothing
' Close stream
Call beCloseStream(hbeStream)
' Command3.Visible = False
' WriteVBRHeader (if we use variable bitrate...)
'Call beWriteVBRHeader(ChangeExt(Text1, "mp3"))
If modGlobal.DelWave = True Then
Kill file
End If
Exit Function
ErrHandler:
' Damn.. Something went wrong and this one should tell what...
' At time of debugin.. This one was place where code ended all the time...
' But now it should never come into this point....
MsgBox Err.Description, vbCritical, "Critical error..."
If WavPtr2 Then GlobalFree WavPtr2
If MP3Ptr2 Then GlobalFree MP3Ptr2
WriteFile.CloseFile
ReadFile.CloseFile
Set WriteFile = Nothing
Set ReadFile = Nothing
Exit Function
End Function