$INCLUDE "RapidQ.inc"
$APPTYPE GUI
$TYPECHECK ON
$RESOURCE PLAYBMP AS "PLAY.BMP"
$RESOURCE STOPBMP AS "STOP.BMP"
DECLARE FUNCTION mciSendString LIB "winmm.dll" ALIAS "mciSendStringA" (lpstrCommand AS STRING, lpstrReturnString AS LONG, uReturnLength AS LONG, hwndCallback AS LONG) AS LONG
DECLARE FUNCTION mciGetErrorString LIB "winmm.dll" ALIAS "mciGetErrorStringA" (dwError AS LONG, lpstrBuffer AS LONG, uLength AS LONG) AS LONG
DECLARE FUNCTION SetWindowPos LIB "user32" ALIAS "SetWindowPos" (hwnd AS LONG, hWndInsertAfter AS LONG,x AS LONG,y AS LONG,cx AS LONG,cy AS LONG,wFlags AS LONG) AS LONG
CONST HWND_TOPMOST = -1
CONST SWP_SHOWWINDOW = &H40
TYPE AviFile EXTENDS QOBJECT
mvarMediaOpen AS LONG
CanvasHandle AS LONG
currentFrame AS LONG
mvarMediaName AS STRING
MediaLenght AS LONG
MediaWidth AS LONG
MediaHeight AS LONG
mvarLastError AS STRING
SUB ParseMediaDimension(mediadim AS STRING)
DIM sPos AS LONG
DIM ePos AS LONG
DIM x AS LONG
DIM y AS LONG
DIM list AS QSTRINGLIST
list.parse(mediadim," ")
AviFile.MediaWidth=VAL(list.item(2))
AviFile.MediaHeight=VAL(list.item(3))
END SUB
FUNCTION GetMciDescription(McierrNr AS LONG) AS STRING
DIM Retval AS LONG
DIM RetString AS STRING
RetString = SPACE$(128)
Retval = mciGetErrorString(McierrNr, VARPTR(RetString), 128)
RetString = LEFT$(retstring,128)
IF Retval = True THEN
AviFile.mvarLastError = RetString
ELSE
RetString = ""
END IF
AviFile.GetMciDescription = RetString
END FUNCTION
SUB MakeMediaClose
DIM Retval AS INTEGER
DIM RetString AS STRING
RetString = SPACE$(128)
Retval = mciSendString("stop MEDIA", VARPTR(RetString), 128, 0)
RetString = SPACE$(128)
Retval = mciSendString("close MEDIA", VARPTR(RetString), 128, 0)
AviFile.mvarMediaOpen = False
END SUB
SUB MakeMediaOpen
IF AviFile.mvarMediaOpen = False THEN
DIM Retval AS INTEGER
DIM RetString AS STRING
RetString = SPACE$(128)
Retval = mciSendString("open " + AviFile.mvarMediaName + " alias MEDIA parent " _
+ STR$(AviFile.CanvasHandle) + " style child", VARPTR(RetString), 128, 0)
IF Retval = 0 THEN
AviFile.mvarMediaOpen = True
ELSE
END IF
END IF
END SUB
FUNCTION GetPos AS LONG
IF AviFile.mvarMediaOpen = True THEN
DIM Retval AS INTEGER
DIM RetString AS STRING
DIM nowPos AS STRING
RetString = SPACE$(128)
Retval = mciSendString("status MEDIA position", VARPTR(RetString), 128, 0)
nowPos = LEFT$(retstring,128)
IF Retval = 0 THEN
AviFile.currentFrame = VAL(nowPos)
END IF
END IF
AviFile.GetPos = AviFile.currentFrame
END FUNCTION
FUNCTION PlayMedia AS LONG
AviFile.MakeMediaOpen
DIM Retval AS INTEGER
DIM RetString AS STRING
RetString = SPACE$(128)
Retval = mciSendString("play MEDIA from " + STR$(AviFile.currentFrame) _
, VARPTR(RetString) , 128, 0)
IF Retval = 0 THEN
AviFile.PlayMedia = True
ELSE
AviFile.PlayMedia = False
END IF
END FUNCTION
SUB StopMedia
IF AviFile.mvarMediaOpen = True THEN
AviFile.GetPos
DIM Retval AS INTEGER
DIM RetString AS STRING
RetString = SPACE$(128)
Retval = mciSendString("stop MEDIA", VARPTR(RetString), 128, 0)
END IF
END SUB
SUB SetMediaName(mName AS STRING)
AviFile.mvarMediaName = mName
AviFile.currentFrame = 0
END SUB
SUB ShowStill
AviFile.MakeMediaOpen
DIM Retval AS INTEGER
DIM RetString AS STRING
RetString = SPACE$(128)
Retval = mciSendString("play MEDIA from " + STR$(AviFile.currentFrame) + " to " _
+ STR$(AviFile.currentFrame), VARPTR(RetString), 128, 0)
IF Retval <> 0 THEN
END IF
END SUB
SUB Setstill(frame AS LONG)
IF AviFile.mvarMediaOpen = True THEN
IF frame < 0 THEN
frame = 0
END IF
IF frame > AviFile.MediaLenght THEN
frame = AviFile.MediaLenght
END IF
AviFile.currentFrame = frame
AviFile.ShowStill
END IF
END SUB
FUNCTION Init AS LONG
IF AviFile.mvarMediaName = "" THEN
AviFile.Init = False
EXIT FUNCTION
END IF
AviFile.Init = True
AviFile.MakeMediaClose
DIM Retval AS INTEGER
DIM RetString AS STRING
DIM errDescript AS STRING
RetString = SPACE$(128)
Retval = mciSendString("open " + AviFile.mvarMediaName + " alias MEDIA" _
, VARPTR(RetString), 128, 0)
IF Retval <> 0 THEN
AviFile.Init = False
EXIT FUNCTION
END IF
RetString = SPACE$(128)
Retval = mciSendString("status MEDIA length", VARPTR(RetString), 128, 0)
RetString = LEFT$(retstring,128)
IF Retval = 0 THEN
AviFile.MediaLenght = VAL(RetString)
ELSE
AviFile.MediaLenght = -1
AviFile.Init = False
END IF
RetString = SPACE$(128)
Retval = mciSendString("where MEDIA source", VARPTR(RetString), 128, 0)
AviFile.ParseMediaDimension (RetString)
RetString = SPACE$(128)
Retval = mciSendString("close MEDIA", VARPTR(RetString), 128, 0)
IF Retval <> 0 THEN
AviFile.Init = False
END IF
END FUNCTION
CONSTRUCTOR
mvarMediaName = ""
MediaLenght = -1
mvarMediaOpen = False
END CONSTRUCTOR
END TYPE
DIM Video AS AviFile
DIM font AS QFONT
font.Name = "Arial"
font.Size = 12
font.AddStyles (fsBold)
DECLARE SUB PlayClick
DECLARE SUB StopClick
DECLARE SUB FormReSize
DECLARE SUB TrackBarChange
DECLARE SUB FormClose (Action AS INTEGER)
DECLARE SUB FormOnKeyDown (Key AS WORD, Shift AS INTEGER)
CREATE Form AS QFORM
CAPTION = "Rapid Q Avi player"
BorderStyle = bsToolWindow
OnKeyDown = FormOnKeyDown
OnResize = FormReSize
OnClose = FormClose
CREATE NavPanel AS QPANEL
Height = 32
BevelOuter = bvNone
CREATE TrackBar AS QTRACKBAR
Left = 70
Height = 18
Top = 8
TickStyle = tsNone
TickMarks = tmBoth
LineSize = 0
OnChange = TrackBarChange
END CREATE
CREATE PlayBtn AS QCOOLBTN
BMPHandle = PLAYBMP
Flat = True
Left = 8: Top = 4: Height = 26: Width = 26
CAPTION = ""
OnClick = PlayClick
font = font
GroupIndex = 2
END CREATE
CREATE StopBtn AS QCOOLBTN
BMPHandle = STOPBMP
Flat = True
Left = 8 + 26: Top = 4: Height = 26: Width = 26
CAPTION = ""
OnClick = StopClick
font = font
GroupIndex = 2
END CREATE
END CREATE
END CREATE
DIM PosTimer AS QTIMER
SUB PostimerOnTimer
DIM Retval AS SHORT
Retval = Video.GetPos
TrackBar.Position = Retval
DOEVENTS
IF Retval = Video.MediaLenght THEN
StopClick
StopBtn.Down = True
END IF
END SUB
PosTimer.Enabled = False
PosTimer.Interval = 1000
PosTimer.OnTimer = PostimerOnTimer
DIM MainMenu AS QMAINMENU
DIM File AS QMENUITEM
DIM Edit AS QMENUITEM
DIM Search AS QMENUITEM
DIM OPEN AS QMENUITEM
DIM Break1 AS QMENUITEM
DIM ExitItem AS QMENUITEM
DIM OpenDialog AS QOPENDIALOG
OpenDialog.Filter = "Video for Windows|*.AVI|"
OpenDialog.CAPTION= "Choose Avi file to open"
SUB FormClose(Action AS INTEGER)
Video.MakeMediaClose
END SUB
SUB ExitClick
Form.CLOSE
END SUB
SUB FileClick
StopClick
StopBtn.Down = True
END SUB
SUB OpenClick
IF OpenDialog.EXECUTE THEN
Form.Cursor = crHourGlass
Video.MakeMediaClose
Video.SetMediaName OpenDialog.FileName
Form.CAPTION = OpenDialog.FileName
IF Video.Init = False THEN
Video.SetMediaName ""
Form.CAPTION = "Can't load: " + Form.CAPTION
Form.Cursor = crDefault
EXIT SUB
END IF
TrackBar.Max = Video.MediaLenght
TrackBar.Position = 0
DIM BorderWidth AS LONG
DIM BorderHeight AS LONG
DIM NavHeight AS LONG
DIM FormCenterX AS LONG
DIM FormCenterY AS LONG
DIM NewX AS LONG
DIM NewY AS LONG
FormCenterX = Form.Left + Form.Width / 2
FormCenterY = Form.Top + Form.Height / 2
NavHeight = NavPanel.Height
BorderWidth = Form.Width - Form.ClientWidth
BorderHeight = Form.Height - Form.ClientHeight
NewX = FormCenterX - (Video.MediaWidth + BorderWidth) / 2
NewY = FormCenterY - (Video.MediaHeight + NavHeight + BorderHeight) / 2
IF NewX < 0 THEN
NewX = 0
END IF
IF NewY < 0 THEN
NewY = 0
END IF
Video.CanvasHandle = Form.Handle
Video.ShowStill
SetWindowPos Form.Handle, 0, NewX, NewY, Video.MediaWidth + BorderWidth, Video.MediaHeight + NavHeight + BorderHeight, SWP_SHOWWINDOW
END IF
END SUB
OPEN.CAPTION = "&Open"
OPEN.OnClick = OpenClick
Break1.CAPTION = "-"
ExitItem.CAPTION = "E&xit"
ExitItem.OnClick = ExitClick
File.CAPTION = "&File"
File.OnClick = FileClick
File.AddItems OPEN,Break1,ExitItem
MainMenu.PARENT = Form
MainMenu.AddItems File
SUB PlayClick
IF Video.PlayMedia = True THEN
PosTimer.Enabled = True
ELSE
StopBtn.Down = True
END IF
END SUB
SUB StopClick
PosTimer.Enabled = False
Video.StopMedia
END SUB
SUB TrackBarChange
Video.Setstill TrackBar.Position
END SUB
SUB FormReSize
NavPanel.Top = Form.ClientHeight - NavPanel.Height
NavPanel.Width = Form.ClientWidth
TrackBar.Width = NavPanel.Width - TrackBar.Left - 10
END SUB
Form.center
Form.SHOWMODAL
|
|