Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Audio in VB Programs

Status
Not open for further replies.

grande

Programmer
Feb 14, 2005
657
CA
I'm trying to make an audio player in VB6, mostly just to prove that I can. But, I'm having some problems.

1. How do I "select" a file, then play, pause, stop, etc. it?
2. How can I read the ID3 tags?
3. (Least important) Does anyone know of a font that looks like an LCD display?

Thanks for any and all help!

-------------------------
Just call me Captain Awesome.
 
The following code should let you play WAV, MIDI, or AVI files.
-----------------------------------------------------------
Step 1. The following code is just a switch to determine the file type and the command to play it:

'full file path of file to play
dim strFileName as string

'select file type to play the file in right format
Select Case UCase(VBA.Right(strFileName, 3))
Case "WAV"
'play a sound
Call sndPlaySound32(strFileName, 0)
Case "MID"
Dim ret As Integer
'assign the file to the sequencer
ret = mciSendString( _
"open " & strFileName & " type sequencer alias MIDIFile", 0&, 0, 0)

'play the file
ret = mciSendString("play MIDIFile ", 0&, 0, 0)

'pause execution
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop

'close the file
ret = mciSendString("close MIDIFile", 0&, 0, 0)
Case "AVI"
ReturnVal& = mciSendString("play " & strFileName & " fullscreen " _
, 0&, 0, 0&)
'pause execution
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop

ReturnVal& = mciSendString("close", 0&, 0, 0&)

Case Else
MsgBox "File type is not supported."
End Select
-----------------------------------------------------------
Step 2. Add a module to the project with the following declarations for playing these file types:

'for playing WAV files
Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

'for playing MIDI files or AVI files
Declare Function mciSendString Lib "winmm.dll" Alias _
"mciSendStringA" (ByVal lpstrCommand As String, ByVal _
lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal _
hwndCallback As Long) As Long


Hope that helps.

I found that it was much simpler to just add a Windows Media Player control to the form, (wmp.dll). It allowed me to play all file types without having to declare them all and it is easy to use.
to start player use:
WMPlayer.URL = strFileName
to stop it use:
WMPlayer.URL =
 
Long time ago I wrote an ActiveX control for displaying text in LED/LCD display format for 7-segment and alpha-numeric displays. I wish I could send it to you.
 
Thanks for all your help, everyone!

Hypetia, do you still have it? If so, email me (matt[dot]grande[at]gmail[dot]com)

Once again, thanks so much!

-------------------------
Just call me Captain Awesome.
 
Captain Awesome, I wish I could send but I won't because sending any code or solution over email is firmly discouraged in this forum. See the 12th point in faq222-2244.

Once again I am sorry. I should not have mentioned it here.
 
Do a search at

Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top