Using Win32 functions in Visual FoxPro Image Gallery
Windows Multimedia
..msdn
AVIFileExit
AVIFileGetStream
AVIFileInfo
AVIFileInit
AVIFileOpen
AVIFileRelease
AVIFileWriteData
AVIStreamGetFrame
AVIStreamGetFrameClose
AVIStreamGetFrameOpen
AVIStreamInfo
AVIStreamLength
AVIStreamReadFormat
AVIStreamRelease
AVIStreamStart
AVIStreamTimeToSample
capCreateCaptureWindow
capGetDriverDescription
DrawDibClose
DrawDibDraw
DrawDibOpen
mciGetDeviceID
mciGetErrorString
mciSendCommand
mciSendString
midiOutClose
midiOutGetDevCaps
midiOutGetNumDevs
midiOutOpen
midiOutReset
midiOutShortMsg
mixerClose
mixerGetControlDetails
mixerGetDevCaps
mixerGetID
mixerGetLineControls
mixerGetLineInfo
mixerGetNumDevs
mixerOpen
mixerSetControlDetails
mmioAscend
mmioClose
mmioCreateChunk
mmioDescend
mmioFlush
mmioOpen
mmioRead
mmioSeek
mmioWrite
PlaySound
sndPlaySound
timeGetDevCaps
waveInAddBuffer
waveInClose
waveInGetDevCaps
waveInGetErrorText
waveInGetNumDevs
waveInGetPosition
waveInOpen
waveInPrepareHeader
waveInReset
waveInStart
waveInStop
waveInUnprepareHeader
waveOutClose
waveOutGetDevCaps
waveOutGetErrorText
waveOutGetNumDevs
waveOutGetPosition
waveOutGetVolume
waveOutOpen
waveOutPrepareHeader
waveOutReset
waveOutSetVolume
waveOutUnprepareHeader
waveOutWrite
Code examples:
Accessing a CD device (cdaudio) with Multimedia Command Strings
Using Multimedia Command Strings to play MIDI files
Using Multimedia Command Strings to play MIDI files

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:
The mciSendString can be used to play various media files including MIDI files.

 
LOCAL oForm As Tform
oForm = CREATEOBJECT("Tform")
oForm.Show(1)
* end of main
 
DEFINE CLASS Tform As Form
    Width=400
    Height=100
    Caption="MIDI Player"
    Autocenter=.T.
    MinButton=.F.
    MaxButton=.F.
    BorderStyle=2
    player=NULL
    lastpath=""
 
    ADD OBJECT Label1 As Label WITH Left=12,;
        Top=18, Autosize=.T., Caption="File:"
 
    ADD OBJECT txtMidiFile As TextBox WITH Left=50,;
        Top=16, Width=310, Height=24
 
    ADD OBJECT cmdMidiFile As CommandButton WITH Left=360,;
        Top=16, Width=24, Height=24, Caption="..."
 
    ADD OBJECT cmdPlay As CommandButton WITH Left=50,;
        Top=50, Width=60, Height=27, Caption="Play"
 
    ADD OBJECT cmdStop As CommandButton WITH Left=110,;
        Top=50, Width=60, Height=27, Caption="Stop"
 
PROCEDURE Init
    THIS.player = CREATEOBJECT("MCIPlayer")
 
PROCEDURE cmdStop.Click
    ThisForm.player.CloseMidi
 
PROCEDURE cmdPlay.Click
    ThisForm.PlayMidiFile
 
PROCEDURE cmdMidiFile.Click
    ThisForm.SelectMidiFile
 
PROCEDURE SelectMidiFile
    LOCAL cCurrentPath, cResult
    cCurrentPath = SYS(5) + SYS(2003)
    IF EMPTY(THIS.lastpath)
        THIS.lastpath = GETENV("SystemRoot") + "\Media"
    ENDIF
 
    IF DIRECTORY(THIS.lastpath)
        SET DEFAULT TO (THIS.lastpath)
    ENDIF
    cResult = GETFILE("MID;MIDI;", "Select MIDI File:", "Open", 0)
    SET DEFAULT TO (cCurrentPath)
 
    IF NOT EMPTY(m.cResult)
        THIS.txtMidiFile.Value = m.cResult
    ENDIF
 
PROCEDURE PlayMidiFile
    LOCAL cFilename
    cFilename = ThisForm.txtMidiFile.Value
    ThisForm.player.PlayMidiFile(cFilename)
 
ENDDEFINE
 
DEFINE CLASS MCIPlayer As Session
PROTECTED MidiAlias
    MidiAlias="midi_"+SYS(2015)
 
PROCEDURE Init
    THIS.declare
 
PROCEDURE Destroy
    THIS.CloseMidi
 
PROCEDURE PlayMidiFile(cFilename)
    IF THIS.OpenMidi(cFilename)
        THIS.PlayMidi
    ENDIF
 
PROTECTED PROCEDURE OpenMidi(cFilename)
    IF NOT FILE(m.cFilename)
        RETURN .F.
    ENDIF
 
    THIS.CloseMidi
    LOCAL nResult
    nResult = mciSendString("open " + m.cFilename +;
        " type sequencer alias "+THIS.MidiAlias, "", 0,0)
 
    IF m.nResult <> 0
        LOCAL cErrMsg
        cErrMsg = THIS.GetErr(m.nResult)
        = MESSAGEBOX(m.cErrMsg, 48, "Failed to open MIDI file")
        RETURN .F.
    ENDIF
RETURN .T.
 
PROTECTED PROCEDURE PlayMidi
    LOCAL nResult
    nResult = mciSendString("play "+THIS.MidiAlias, "", 0,0)
 
    IF m.nResult <> 0
        LOCAL cErrMsg
        cErrMsg = THIS.GetErr(m.nResult)
        = MESSAGEBOX(m.cErrMsg, 48, "Failed to play MIDI file")
    ENDIF
 
PROCEDURE CloseMidi
    = mciSendString("stop "+THIS.MidiAlias, "", 0,0)
    = mciSendString("close "+THIS.MidiAlias, "", 0,0)
 
PROTECTED FUNCTION GetErr(lnError)
    LOCAL cBuffer
    cBuffer = REPLICATE(CHR(0), 250)
    = mciGetErrorString(lnError, @cBuffer, LEN(cBuffer))
RETURN SUBSTR(cBuffer, 1, AT(Chr(0),cBuffer)-1)
 
PROTECTED PROCEDURE declare
    DECLARE INTEGER mciSendString IN winmm;
        STRING lpszCommand, STRING @lpszReturnString,;
        INTEGER cchReturn, INTEGER hwndCallback
 
    DECLARE INTEGER mciGetErrorString IN winmm;
        INTEGER fdwError, STRING @lpszErrorText,;
        INTEGER cchErrorText
 
ENDDEFINE
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
3041 bytes  
Created: 2008-04-14 18:31:22  
Modified: 2008-04-14 18:35:06  
Visits in 7 days: 74  
Listed functions:
mciGetErrorString
mciSendString
Printer friendly API declarations
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (107.22.127.92)
4 sec.Example: 'Displaying dimmed window behind VFP top-level form'
7.49 hrs.Function: 'GdipFillRectangle'
 Function: 'EnumServicesStatus'
Function group: 'Service'
10.26 hrs.Example: 'How to print a bitmap file'
 Function: 'InternetCheckConnection'
Google
Advertise here!