Welcome to MSDN Blogs Sign in | Join | Help

Fox plays music

I received a customer question:

 

I have searched the net and asked as many people as I could and could not get an answer, so I am bothering you.
Do you know of a way to get VFP to play mp3 format tunes? There must be a way to use a media player driver or ActiveX to make this happen. Any ideas?

 

For a simple way to start an mp3 file, try this in the command window:

!start d:\piano.mp3

 

A more elegant solution: try out the Fox Media player that comes with VFP9:  Start the Task Pane: choose Solution Samples->New in VFP 9->Fox Media Player

 

 

Or you can run this code from that sample. (I tried it in VFP8 and it works: I had to remove some VFP 9 specific features, such as anchoring).

 

playit("D:\piano.mp3")

*playit("D:\Calvinh\My Music\Claude Bolling\2003. Pariswing\02. La Mer.wma")

PROCEDURE playit(tcURL, tnDrive)

 

LOCAL loError, loCD

IF VARTYPE(tcURL)#"C" OR EMPTY(tcURL)

      * Sample URL

      tcURL = "http://radio.livephish.com:8000"

ENDIF

 

      IF TYPE("_SCREEN.oWMP")#"O"

            _SCREEN.ADDOBJECT("oWMP","WMPContainer")

            WITH _SCREEN.oWMP

                  .HEIGHT = _SCREEN.HEIGHT

                  .WIDTH = _SCREEN.WIDTH

                  .VISIBLE=.T.

            ENDWITH

      ENDIF

      IF UPPER(tcURL)=="CD"

            IF tnDrive = -1

                  RETURN

            ENDIF

            loCD = _SCREEN.oWMP.oleWMP.cdromCollection.ITEM(tnDrive)

            _SCREEN.oWMP.oleWMP.currentPlaylist = loCD.Playlist

      ELSE

            _SCREEN.oWMP.oleWMP.url = tcURL

      ENDIF

 

 

 

 

 

 

*---------- CLASSES ----------------------------------

DEFINE CLASS WMPContainer AS CONTAINER

      oWMPToolBar = NULL

 

      ADD OBJECT oleWMP AS OLECONTROL WITH ;

            OLECLASS = 'WMPlayer.OCX'

 

      ADD OBJECT tmrWMP1 AS tmrWMP

 

      PROCEDURE INIT

            THIS.oleWMP.WIDTH = THIS.WIDTH

            THIS.oleWMP.HEIGHT = THIS.HEIGHT

            THIS.oWMPToolBar = ;

                  NEWOBJECT('WMPToolBar', SYS(16), NULL, THIS)

            THIS.oWMPToolBar.VISIBLE = .T.

      ENDPROC

 

      PROCEDURE RELEASE

            _SCREEN.LOCKSCREEN = .T.

            THIS.REMOVEOBJECT('oleWMP')

            RELEASE THIS

            _SCREEN.LOCKSCREEN = .F.

      ENDPROC

 

      PROCEDURE oleWMP.DoubleClick(p1,p2,p3,p4)

            THIS.VISIBLE = .F.

            THIS.PARENT.VISIBLE = .F.

            THIS.PARENT.oWMPToolBar = NULL

            THIS.PARENT.tmrWMP1.ENABLED = .T.

      ENDPROC

ENDDEFINE

 

 

 

 

*--------------------------------------------

DEFINE CLASS WMPToolBar AS TOOLBAR

      SHOWTIPS = .T.

      CAPTION = 'Fox Media Player'

      WMPContainer = NULL

 

      ADD OBJECT CmdClose AS COMMANDBUTTON WITH ;

            TOOLTIPTEXT = 'Close Fox Media Player', ;

            PICTURE = HOME() + 'tools\test\close.bmp', ;

            SPECIALEFFECT = 2, ;

            HEIGHT = 22, WIDTH = 140

 

      PROC INIT(WMPContainer AS OBJECT)

            THIS.WMPContainer = WMPContainer

      ENDPROC

 

      PROCEDURE CmdClose.CLICK

            THIS.PARENT.WMPContainer.oleWMP.DoubleClick()

      ENDPROC

ENDDEFINE

 

 

 

 

*--------------------------------------------

DEFINE CLASS tmrWMP AS TIMER

      INTERVAL = 500

      ENABLED = .F.

      PROCEDURE TIMER

            THIS.PARENT.RELEASE()

      ENDPROC

ENDDEFINE

 

 

 

46181

Published Thursday, December 16, 2004 9:54 AM by Calvin_Hsia

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Fox plays music

Thursday, December 16, 2004 1:22 PM by Michael
Hey Calvin,

Wasn't VFP 9 suppose to RTM yesterday? Has it happened? Or has it been delayed?

Thanks,

Mike

# re: Fox plays music

Thursday, December 16, 2004 3:59 PM by Grady
I do not have VFP9 yet and, being much less skilled than you, I cannot get any of the code you supplied to work for me in my VFP 8. I need a little coaching, please.

# re: Fox plays music

Thursday, December 16, 2004 4:00 PM by Grady
I do not have VFP9 yet and, being much less skilled than you, I unable to get any of the code you supplied to work for me in my VFP 8. I need a little coaching, please.

# re: Fox plays music

Thursday, December 16, 2004 4:27 PM by Grady
Scratch that - I got it working and all is well.

Tell Mr. Gates that Grady says Hi.

# re: Fox plays music

Saturday, January 08, 2005 12:12 PM by Grady McCue
A lot could be done with:

Set bell on
Set Bell1 sound to WMA
Set Bell2 sound to WMA (Or WAV or MP3)
?? Chr(7,Bell1)
?? Chr(7,Bell2)

Bells one and two would allow cross fading of sound within the VFP environment.

# re: Fox plays music

Tuesday, October 24, 2006 9:06 AM by edyshor

you could have put a comprehensive example of using the MCI .. i know it's in the solution samples .. but many forgtet about it and interestingly enough don't think that such an 'advanced' techniquie could be found in the oh so ready aviable solution samples ..

it was better for me, axactly what i needed . .full control, lightweight comparative to media player automation, but i search around for some examples of command strings (great stuff btw .. the interaction almost human like achived with 'command strings')

thanks. great blog, love your examples .. keep it up :)

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker