Home Page

R. T. RUSSELL

BBC BASIC for Windows

Simple Media Player



This program is a simple media player, which will play a wide range of audio and video file formats such as WAV, MP3, WMA, MID, AVI, MPG and WMV (the exact list will depend on the codecs installed on your PC). It displays a small window containing buttons for Open, Stop, Play and Pause operations. Whilst playing the elapsed time is displayed.

Download PLAYER.BBC Run PLAYER.EXE

     REM Simple media player in BBC BASIC for Windows, RTR 02-Nov-2004, 01-May-2007
     REM!Exefile C:\www\bbcwin\examples\player.exe

     
INSTALL @lib$+"WINLIB"
     INSTALL @lib$+"WINLIB3"

     MCI_OPEN   = &803
     MCI_CLOSE  = &804
     MCI_PLAY   = &806
     MCI_SEEK   = &807
     MCI_STOP   = &808
     MCI_SET    = &80D
     MCI_STATUS = &814
     MCI_ALL_DEVICE_ID   = -1
     MCI_WAIT            = 2
     MCI_FROM            = 4
     MCI_TO              = 8
     MCI_STATUS_POSITION = 2
     MCI_STATUS_ITEM     = &100
     MCI_OPEN_ELEMENT    = &200
     MCI_SET_TIME_FORMAT = &400

     VDU 23,22,154;72;19,36,16,0
     SYS "SetWindowPos",@hwnd%,-1,0,0,0,0,3
     COLOUR 7,20,255,50
     DeviceID% = 0

     nbuttons% = 6
     DIM bu%(nbuttons%-1), id%(nbuttons%-1), bu$(nbuttons%-1)
     bu%() = 0,0,7,-1,-1,-1
     id%() = 0,0,900,901,902,-903
     bu$() = "","","Open","Stop","Play","Pause"
     toolbar% = FN_createtoolbar(nbuttons%, bu%(), id%())
     PROC_addtooltips(toolbar%, nbuttons%, bu$(), id%())
     id%() = 901,902,903,904,905
     IF FN_custombuttons(toolbar%, @dir$+"CDPLAYER.BMP", 5, id%()) = 0 THEN
       SYS
"MessageBox", @hwnd%, "Cannot load CDPLAYER.BMP", 0, 48
       QUIT
     ENDIF

     DIM
Ofn{lStructSize%, hwndOwner%, hInstance%, lpstrFilter%, \
     
\      lpstrCustomFilter%, nMaxCustFilter%, nFilterIndex%, \
     
\      lpstrFile%, nMaxFile%, lpstrFileTitle%, \
     
\      nMaxFileTitle%, lpstrInitialDir%, lpstrTitle%, \
     
\      flags%, nFileOffset{l&,h&}, nFileExtension{l&,h&}, \
     
\      lpstrDefExt%, lCustData%, lpfnHook%, lpTemplateName%}
     DIM FileName% 255
     filter$ = "Media files"+CHR$0+"*.MP3;*.WMA;*.MID;*.MIDI;*.RMI;*.WAV;*.AVI;*.MPG;*.MP2;*.WMV;*.MOV;*.MPEG"+CHR$0+"All files"+CHR$0+"*.*"+CHR$0+CHR$0
     Ofn.lStructSize% = DIM(Ofn{})
     Ofn.hwndOwner% = @hwnd%
     Ofn.lpstrFilter% = !^filter$
     Ofn.lpstrFile% = FileName%
     Ofn.nMaxFile% = 256
     Ofn.flags% = 6 : REM OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY

     
DIM mciOpenParms{dwCallback%, wDeviceID%, lpstrDeviceType%, lpstrElementName%, lpstrAlias%}
     DIM mciPlayParms{dwCallback%, dwFrom%, dwTo%}
     DIM mciSetParms{dwCallback%, dwTimeFormat%, dwAudio%}
     DIM mciStatusParms{dwCallback%, dwReturn%, dwItem%, dwTrack%}
     DIM mciSeekParms{dwCallback%, dwTo%}

     ON CLOSE PROCstop:PROCclose:PROC_removetoolbar:QUIT
     ON ERROR SYS
"MessageBox", @hwnd%, REPORT$, 0, 48
     ON SYS Click% = @wparam%:RETURN

     
Click% = -1
     Pause% = FALSE
     REPEAT
       
temp% = INKEY(1)
       IF temp% = -1 SWAP Click%,temp%
       CASE temp% OF
         WHEN
900: PROCstop:Pause% = FALSE:PROCclose:PROCopen:PROCplay(0)
         WHEN 901: PROCstop:Pause% = FALSE:PROCseek(0)
         WHEN 902: PROCstop:Pause% = FALSE:PROCplay(0)
         WHEN 903: PROCstop:Pause% = NOT Pause%:IF NOT Pause% PROCplay(mciStatusParms.dwReturn%)
       ENDCASE
       IF
DeviceID% THEN
         
mciStatusParms.dwItem% = MCI_STATUS_POSITION
         SYS "mciSendCommand", DeviceID%, MCI_STATUS, MCI_STATUS_ITEM, mciStatusParms{}
         PROCreport(mciStatusParms.dwReturn%)
       ENDIF
       SYS
"SendMessage", toolbar%, 1041, 903, 4 OR (Pause% AND 1)
     UNTIL FALSE

     
DEF PROCreport(N%):LOCAL @%
     @% = &1020205
     VDU 30
     PRINT 'LEFT$(RIGHT$(" "+STR$(N%DIV60000),5),2)":"RIGHT$("0"+STR$((N%MOD60000)/1000),5);
     ENDPROC

     
DEF PROCopen:LOCAL F%, R%
     SYS "GetOpenFileName", Ofn{} TO R%
     IF R% = 0 ENDPROC
     
mciOpenParms.wDeviceID% = 0
     mciOpenParms.lpstrDeviceType% = MCI_ALL_DEVICE_ID
     mciOpenParms.lpstrElementName% = FileName%
     SYS "mciSendCommand", 0, MCI_OPEN, MCI_OPEN_ELEMENT, mciOpenParms{} TO R%
     IF R% ERROR 100, "No codec for file format"
     DeviceID% = mciOpenParms.wDeviceID%
     SYS "mciSendCommand", DeviceID%, MCI_SET, MCI_SET_TIME_FORMAT, mciSetParms{}
     SYS "GetFullPathName", FileName%, 256, FileName%, ^F%
     SYS "SetWindowText", @hwnd%, F%
     ENDPROC

     
DEF PROCplay(mciPlayParms.dwFrom%)
     IF DeviceID% = 0 ENDPROC
     SYS
"mciSendCommand", DeviceID%, MCI_PLAY, MCI_FROM, mciPlayParms{}
     ENDPROC

     
DEF PROCseek(mciSeekParms.dwTo%)
     IF DeviceID% = 0 ENDPROC
     SYS
"mciSendCommand", DeviceID%, MCI_SEEK, MCI_TO, mciSeekParms{}
     ENDPROC

     
DEF PROCstop
     IF DeviceID% = 0 ENDPROC
     SYS
"mciSendCommand", DeviceID%, MCI_STOP, MCI_WAIT, 0
     ENDPROC

     
DEF PROCclose
     IF DeviceID% = 0 ENDPROC
     SYS
"mciSendCommand", DeviceID%, MCI_CLOSE, MCI_WAIT, 0
     DeviceID% = 0
     ENDPROC


Home - Products - Contact us

Best viewed with Any Browser Valid HTML 3.2!
© Richard Russell 2007