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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to programatically play WAV or MP3 files

Status
Not open for further replies.

Sammybobo

Programmer
Apr 4, 2003
87
US
Could someone please help me on how to programmatically play a sound file, particularly MP3 and WAV files within an application written in VF 8 or 7? I would prefer that it would not display the Media application playing the file, like Windows Media does. Thank you.
 
This should do it. Read the comments. It can also be used to open or print other apps including text, doc, web-url's etc...


Code:
appLaunch("myfile.wav")

*****************************************
FUNCTION appLaunch
PARAMETER tcOutFile,tcCmd  

IF PCOUNT() < 1
	MESSAGEBOX("You did not provide a filename.","AppLauch Method")
	RETURN
ENDIF	

IF PCOUNT() < 2
	tcCmd = "Open"
ENDIF	
	
tcCmd = PROPER(m.tcCmd)

* This code was originally located in Ken Levy's DBF2XML program so blame 
* Ken for the bugs :)

* API Call to communicate with an application based on the registered
* file-type.  
* For example: 
* On my computer txt is notepad; DOC is word

DECLARE INTEGER ShellExecute ;
	    IN SHELL32.DLL ;
	    INTEGER nWinHandle,;
	    STRING cOperation,;   
	    STRING cFileName,;
	    STRING cParameters,;
	    STRING cDirectory,;
	    INTEGER nShowWindow
	    
* tip: to determine commands available for each filetype
* Launch explorer
* go to View / Folder Options
* Select the File Type Tag	
* go to the item you wish to look up (example Acrobat)
* Press Edit
* You will see acrobat has Open, Print, and Printto option types.    
	    
*IF !FILE(tcOutFile)	    
*	MESSAGEBOX(tcOutFile + " does not exist!","AppLauch Method -- AppLauch Method")
*ELSE	

	* play with this.  
	* by adding the ,0 instead of ,1 I was able to get it to
	* print directly without opening the document on my sceen.
	
	
	* this is handy if you wish to print a pdf, word document, 
	* spreadsheet, text file, etc. from within your applicaiton.
	IF m.tcCmd = "Print"
		lnFileStatus = ShellExecute(0,"&tcCmd",tcOutFile,"","",0)
	ELSE
		lnFileStatus = ShellExecute(0,"&tcCmd",tcOutFile,"","",1)
	ENDIF	
	DO CASE 
	CASE m.lnFileStatus > 32
		* successful open
	CASE m.lnFileStatus = 2 
		MESSAGEBOX("Bad Association (for example, invalid URL)",;
			"AppLauch Method -- AppLauch Method")
	CASE m.lnFileStatus = 29
		MESSAGEBOX("Failure to load application","AppLauch Method -- AppLauch Method")
	CASE m.lnFileStatus = 30
		MESSAGEBOX("Application is busy","AppLauch Method -- AppLauch Method")
	CASE m.lnFileStatus = 31
		MESSAGEBOX("No application association with specified "+;
			"command: " + m.tcCmd,"AppLauch Method -- AppLauch Method")
	OTHERWISE
		MESSAGEBOX("Unknown Error","AppLauch Method -- AppLauch Method")
		RETURN .F.
	ENDCASE		
*ENDIF

Jim Osieczonek
Delta Business Group, LLC
 
This will work... but I am not sure if it will get around the player launching. Let us know how this turns out.

Jim Osieczonek
Delta Business Group, LLC
 
Here's a quick and dirty way to play "wav" files.

You shouldn't issue another bell until the wav is finished.

You ask - How do I know the wav is finished?

I assume it would be an API call, but I haven't done it.

Darrell

[tt]
local cOldWav
cOldWav = sys(2001,"bell",1)
set bell to "C:\WINDOWS\Media\tada.wav"
?? chr(7)
set bell to cOldWav
[/tt]
 
And here's a method of playing any type of audio file
using the windows media player ActiveX object.

Note: I'm running XP with MediaPlayer 9.x

Download the Media Player SDK and have fun!


Darrell

[tt]
public oMediaPlayer
oMediaPlayer = createobject("clsMediaPlayer")
oMediaPlayer.oWmi.object.settings.volume = 50
oMediaPlayer.oWmi.object.url = "C:\WINDOWS\Media\town.mid"

Define class clsMediaPlayer as form

Add object oWmi as olecontrol with;
oleclass = "WMPlayer.OCX.7"

Enddefine
[/tt]
 
Great, guys. Thanks much for your help. I found the MCI form on the Solution Samples and liked it very much. However, since I only want to play sound I am looking for a way to retain the Progress Bar and the Play/Stop/Pause buttons but put all of these objects on the form of my own appliation. I am having difficulites with how to accomplish this. How can I incorporate MCI in my app form and send a filename to it to play automatically without going through the File Open dialog? Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top