Thread View: comp.lang.basic.visual.misc
3 messages
3 total messages
Started by Curious Student
Sat, 19 Jun 2004 13:37
Playing a wav file through MCI
Author: Curious Student
Date: Sat, 19 Jun 2004 13:37
Date: Sat, 19 Jun 2004 13:37
72 lines
3316 bytes
3316 bytes
I get an error while playing a wav file. I am using VB6 and the MCI
(winmm.dll) interface. But the front end doesn't matter. I need help
resolving an error that MCI throws back on me when I open the device.
The error comes as a return value to the "Open" string message.
[CODE]
Private Sub Form_Load()
BoolRecordingOn = False
If waveOutGetNumDevs() <= 0 Then MsgBox "Your system can't play
sounds.", vbCritical, "Sound Card Not Available"
End Sub
Private Sub cmdOpen_Click()
c.CancelError = False
c.ShowOpen
StrFile = vbNullString
If Trim(c.FileName) <> vbNullString Then StrFile =
GetShortFileName(c.FileName)
End Sub
Private Sub cmdPlay_Click()
If StrFile = vbNullString Then Exit Sub
BoolRecordingOn = False
cmdRecord.Enabled = False
StrCommand = "Open " & StrFile & " type waveaudio alias StrFile1"
LngRetVal = mciSendString(StrCommand, vbNullString, 0&, 0&)
If LngRetVal <> 0 Then DisplayError (LngRetVal)
StrCommand = "Play StrFile1"
LngRetVal = mciSendString(StrCommand, 0, 0, 0)
If LngRetVal <> 0 Then DisplayError (LngRetVal)
End Sub
Private Sub DisplayError(ByVal errcode As Long)
Dim errstr As String
Dim retval As Long
errstr = Space(255)
retval = mciGetErrorString(errcode, errstr, Len(errstr))
errstr = Left(errstr, InStr(errstr, vbNullChar) - 1)
retval = MsgBox(errstr, vbOKOnly Or vbCritical)
End Sub
Public Function GetShortFileName(ByVal FileName As String) As String
Dim StrShortFileName As String
Dim LngRetVal As Long
GetShortFileName = vbNullString
StrShortFileName = Space(255)
LngRetVal = GetShortPathName(FileName, StrShortFileName,
Len(StrShortFileName))
Debug.Assert LngRetVal <> 0
StrShortFileName = Left(StrShortFileName, LngRetVal)
GetShortFileName = Trim(StrShortFileName)
End Function
[/CODE]
I get this error message:
[QUOTE][B]No wave device that can play files in the current format is
installed. Use the Add/Remove Hardware Wizard in Control Panel to
install the wave device.[/B][/QUOTE]
If I didn't the device to support the WAV file, how is it that other
programs like WinAmp can play the same WAV file. Surely I have the
necessary stuff on my system. What do I do?
Re: Playing a wav file through MCI
Author: Gale Green
Date: Sat, 19 Jun 2004 14:40
Date: Sat, 19 Jun 2004 14:40
60 lines
3006 bytes
3006 bytes
On 19 Jun 2004 06:37:40 -0700, estudiantin@rediffmail.com (Curious
Student) wrote:
> I get an error while playing a wav file. I am using VB6 and the MCI
> (winmm.dll) interface. But the front end doesn't matter. I need help
> resolving an error that MCI throws back on me when I open the device.
> The error comes as a return value to the "Open" string message.
I copied all your code into a new project, added declarations for all
the variables, and it worked first time.
I believe you may be missing a link in SYSTEM.INI:
waveaudio=mciwave.drv
in group [mci]
You don't say which version of Windows you're using but I believe the
code below will work on all versions because on NT clones
WritePrivateProfileString maps accesses to system INI files to the
registry automatically.
However, if you have Win 95/98/Me, and this project is just for your
own use, then you can edit SYSTEM.INI manually, to include the above
line.
Gale.
===============
Private Declare Function GetWindowsDirectory _
Lib "kernel32" _
Alias "GetWindowsDirectoryA" ( _
ByVal lpBuffer As String, _
ByVal nSize As Long) As Long
Private Declare Function WritePrivateProfileString _
Lib "kernel32" _
Alias "WritePrivateProfileStringA" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpString As Any, _
ByVal lpFileName As String) As Long
Dim MyLen As Long, _
Temp As String * 255, _
WinDir As String, _
DeviceType As String, _
DriverName As String
DeviceType = "waveaudio"
DriverName = "mciwave.drv"
MyLen = GetWindowsDirectory(Temp, 255)
WinDir = Left$(Temp, MyLen)
MyLen = WritePrivateProfileString( _
"MCI", _
DeviceType, _
DriverName, _
WinDir & "\system.ini")
Re: Playing a wav file through MCI
Author: Gale Green
Date: Sat, 19 Jun 2004 14:48
Date: Sat, 19 Jun 2004 14:48
11 lines
1260 bytes
1260 bytes
I forgot... it's also worth checking that the other link is in place, in WIN.INI. There should be a line wav=waveaudio in group [mci extensions] Gale.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads