Partager via


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 = "https://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

Comments

  • Anonymous
    December 16, 2004
    Hey Calvin,

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

    Thanks,

    Mike

  • Anonymous
    December 16, 2004
    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.

  • Anonymous
    December 16, 2004
    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.

  • Anonymous
    December 16, 2004
    Scratch that - I got it working and all is well.

    Tell Mr. Gates that Grady says Hi.

  • Anonymous
    January 08, 2005
    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.

  • Anonymous
    October 24, 2006
    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 :)

  • Anonymous
    October 27, 2006
    PingBack from http://www.pusatit.com/information-technology-computer/software-play-mp3-music-with-foxpro-hardware-application.html

  • Anonymous
    January 20, 2009
    The comment has been removed

  • Anonymous
    June 08, 2009
    PingBack from http://quickdietsite.info/story.php?id=8614

  • Anonymous
    November 13, 2009
    Hola Buenas tardes. Podrias por favor enviarme mas detalle hacerca de este tema espesificamente. Gracias.