Documentation component by D.Glodt (c)2000-2004 Appendix A: QVIDEO

QVIDEO Component

QVIDEO is a media component used to play vidéo file.


QVIDEO Properties
Field Type R/W Default




Timer QTIMER RW
Controle the fréquency of évent OnChange. 
Lenght LONG R
Lenght of  video file (images number)
LenghtTime LONG R
Lenght of video file (seconds)
State INTEGER R VD_CLOSE
State of media video player,can be VD_PLAY,VD_STOP,VD_PAUSE. 
Handle LONG R
Handle of control. 
Parent LONG RW
Handle QFORM or 0 for window of média player
FileOpen BOOLEAN R False
It's at true if a video file is open. 
Left SHORT RW
Top SHORT RW
Width SHORT RW
Height SHORT RW
ImgWidth SHORT R
Image width of vidéo file
ImgHeight SHORT R
Image height of vidéo file
CurrentFrame LONG RW
Current position of player. 
AudioOff BOOLEAN RW False
Without sound if true.
Error STRING R
Text error if the OPEN method return FALSE.
Caption STRING RW
Title window média player
BorderStyle INTEGER RW bsSizeable
Window style of media player when his parent is the desk,can be bsNone ou bsSizeable
WindowState INTEGER RW wsNormal
Window state of media player when his parent is the desk,can be wsNormal ou wsMinimized ou wsMaximized
Volume INTEGER RW 0
DeviceType STRING RW
Codec type , example:MpegVideo

QVIDEO Methods
Method Type Description Params




Close SUB Close the media player. 0
Open FUNCTION(FileName as string) Open video file. 2
Show SUB Show video. 0
Play SUB Play the video file. 0
Stop SUB Stop the player. 0
Pause SUB Set the player in pause mode. 0

QVIDEO Events
Event Type Occurs when... Params




OnChange (position as long,timePos as long) Position of player in mode play.
The parameter position give the position by image,
the parameter timePos give the position by seconds.
2

QVIDEO Examples

'************************************************************************** 
'* application:player video                                               * 
'* auteur:D.Glodt                                                         * 
'* date:17-1-2004                                                         * 
'************************************************************************** 
$OPTION ICON "video.ico"
$TYPECHECK ON
$Include "Rapidq.inc"
$include "Object\QVideo.inc"

$RESOURCE PLAYBMP as "play.bmp"
$RESOURCE STOPBMP as "Stop.bmp"
$RESOURCE PAUSEBMP as "Pause.bmp"
$RESOURCE SPEAKERBMP as "Speaker.bmp"
$RESOURCE SPEAKEROFFBMP as "SpeakerOff.bmp"

Declare Sub PaintForm
Declare Sub ResizeForm
Declare Sub Play
Declare Sub Stop
Declare Sub Pause
Declare Sub Open
Declare Sub Close
Declare Sub Quitter
Declare Sub TrackBarChange
Declare Sub PostimerOnTimer(Position as long,timePos as long)
Declare Sub Zoom1
Declare Sub Zoom2
Declare Sub Zoom3
Declare Sub Zoom4
Declare Sub FullScreen
Declare Sub Speaker
Declare Sub EditSeq
Declare Sub PlaySeq
Declare Sub AddSeq
Declare Sub DelSeq
Declare Sub DelAllSeq
Declare Sub CloseSeq
Declare Sub VolumeChange

const FormWidth=288
const FormHeight=290
Dim OpenDialog as QOpenDialog
OpenDialog.Filter="Fichier vidéo(tout type)|*.avi;*.mpg;*.mpeg;*.mov|Fichier avi|*.avi|Fichier MPEG|*.mpg;*.mpeg|Fichier MOV|*.mov|"
OpenDialog.Caption= "Selectionner une vidéo"
Dim video as QVideo
video.DeviceType="MpegVideo"
video.OnChange=PostimerOnTimer
video.timer.interval=200
Dim Counter as integer
Dim flagSeq as integer
Dim flagSpeaker as integer
flagSpeaker=false
Dim FileName as string

CREATE Form2 AS QFORM
    Caption="Selection séquence"
    Width=430
    Height=230
    Center
    BorderStyle=bsDialog
    CREATE ListSeq AS QLISTBOX
        Left=10
        Top=10
        Width=400
        Height=150
    END CREATE
    CREATE BtAdd AS QBUTTON
        Caption="Ajouter"
        Left=10
        Top=170 
        TabOrder=2
        OnClick=AddSeq
    END CREATE
    CREATE BtDel AS QBUTTON
        Caption="Supprimer"
        Left=93
        Top=170
        TabOrder=3
        OnClick=DelSeq
    END CREATE
    CREATE BtDelAll AS QBUTTON
        Caption="Nouveau"
        Left=175
        Top=170
        TabOrder=4
        OnClick=DelAllSeq
    END CREATE
    CREATE BtQuit AS QBUTTON
        Caption="Fermer"
        Left=335
        Top=170
        TabOrder=1
        OnClick=CloseSeq
    END CREATE
END CREATE

CREATE Form3 AS QFORM
  BorderStyle=bsNone
  left=0
  top=0
  width=Screen.width
  height=Screen.height
  color=&H0
  cursor=crnone
  OnKeyPress=Stop
END CREATE

CREATE Form AS QFORM
    Caption="Vidéo"
    Width=FormWidth
    Height=FormHeight
    Center
    BorderStyle=bsSingle
    DelBorderIcons 2
    OnPaint=PaintForm
    OnResize=ResizeForm
    OnClose=Quitter
    CREATE MENU AS QMAINMENU
      CREATE FileMenu AS QMENUITEM
        Caption="&Fichier"
        CREATE Item1 AS QMENUITEM
          Caption="&Ouvrir"
          OnClick=Open
        END CREATE
        CREATE Item2 AS QMENUITEM
          Caption="&Fermer"
          OnClick=Close
        END CREATE
        CREATE Item3 AS QMENUITEM
          Caption="-"
        END CREATE
        CREATE Item4 AS QMENUITEM
          Caption="&Quitter"
          OnClick=Quitter
        END CREATE
      END CREATE
      CREATE Display AS QMENUITEM
        Caption="&Affichage"
        CREATE Item11 AS QMENUITEM
          Caption="&Zoom"
          Enabled=false
          CREATE Item21 AS QMENUITEM
            Caption="&Zoom 50%"
            OnClick=Zoom1
          END CREATE
          CREATE Item22 AS QMENUITEM
            Caption="&Zoom 100%"
            Checked=true
            OnClick=Zoom2
          END CREATE
          CREATE Item23 AS QMENUITEM
            Caption="&Zoom 150%"
            OnClick=Zoom3
          END CREATE
          CREATE Item24 AS QMENUITEM
            Caption="&Zoom 200%"
            OnClick=Zoom4
          END CREATE
        END CREATE
        CREATE Item25 AS QMENUITEM
          Caption="&Plein écran"
          OnClick=FullScreen
        END CREATE
      END CREATE
      CREATE Sequence AS QMENUITEM
        Caption="&Séquence"
        CREATE Item13 AS QMENUITEM
          Caption="&Edition"
          OnClick=EditSeq
        END CREATE
        CREATE Item14 AS QMENUITEM
          Caption="&Lancer séquence"
          OnClick=PlaySeq
          Enabled=false
        END CREATE
      END CREATE
    END CREATE
    CREATE Panel1 AS QPANEL
        Left=0
        Top=171
        Width=281
        Height=80
        BevelOuter=bvNone
        CREATE BtPlay AS QCOOLBTN
            BMPHandle=PLAYBMP
            Left=8
            Top=6
            Width=26
            Height=26
            Flat=true
            Hint="Play"
            ShowHint=true
            GroupIndex=1
            OnClick=Play
            Enabled=false
        END CREATE
        CREATE BtStop AS QCOOLBTN
            BMPHandle=STOPBMP
            Left=46
            Top=6
            Width=26
            Height=26
            Flat=true
            Hint="Stop"
            ShowHint=true
            GroupIndex=1
            OnClick=Stop
            Enabled=false
        END CREATE
        CREATE BtPause AS QCOOLBTN
            BMPHandle=PAUSEBMP
            Left=84
            Top=6
            Width=26
            Height=26
            Flat=true
            GroupIndex=1
            Hint="Pause"
            ShowHint=true
            OnClick=Pause
            Enabled=false
        END CREATE
        CREATE BtSpeaker AS QCOOLBTN
            BMPHandle=SPEAKERBMP
            Left=122
            Top=6
            Width=26
            Height=26
            Flat=true
            Hint="Son"
            ShowHint=true
            OnClick=Speaker
            Enabled=false
        END CREATE
        CREATE TrackBar1 AS QTRACKBAR
            TickMarks=tmBoth
            TickStyle=tsNone
            Left=2
            Top=36
            LineSize=0
            Width=272
            Height=21
            Hint="Position"
            ShowHint=true
            OnChange=TrackBarChange
            Enabled=false
        END CREATE
        CREATE TrackBar2 AS QTRACKBAR
            TickMarks=tmTopLeft
            TickStyle=tsnone
            Left=173
            Top=10
            LineSize=0
            Width=100
            Height=21
            Hint="Volume"
            ShowHint=true
            OnChange=VolumeChange
            Enabled=false
            Min=0
            Max=100
        END CREATE
        CREATE infos AS QSTATUSBAR
          SizeGrip=false
          AddPanels "Format:","Durée:",""
          Panel(0).width=100
          Panel(1).width=100
        END CREATE
    END CREATE
END CREATE
video.parent=form.handle
Form.ShowModal

Sub PaintForm
  form.FillRect(0,0,form.clientWidth,(form.clientHeight-panel1.height),&H0)
End Sub

Sub ResizeForm
  Panel1.Top=form.ClientHeight-Panel1.Height
  Panel1.Width=form.ClientWidth
  TrackBar1.width=Panel1.width-10
End Sub

Function GetMinutes(seconds as long) as string
  dim min as integer
  dim sec as integer
  
  min=seconds/60
  sec=seconds mod 60
  if sec<10 then
    result=str$(min)+":0"+str$(sec)
  else
    result=str$(min)+":"+str$(sec)
  end if
End Function

Sub Open  
  If OpenDialog.Execute Then
   video.close
   if video.open(OpenDialog.FileName) then
     FileName=OpenDialog.FileName
     form.Width=video.width+(form.width-form.clientWidth)+2
     form.Height=video.height+panel1.height+(form.height-form.clientHeight)
     ResizeForm
     TrackBar1.Enabled=true
     TrackBar2.Enabled=true
     TrackBar1.Max=video.lenght
     TrackBar1.Position=0
     if item21.checked then zoom1
     if item23.checked then zoom3
     if item24.checked then zoom4
     BtStop.Enabled=true
     BtPlay.Enabled=true
     BtPause.Enabled=true
     BtSpeaker.Enabled=true
     BtStop.Down=True
     Item11.Enabled=true
     video.show
     form.caption="Vidéo - "+right$(OpenDialog.FileName,Len(OpenDialog.FileName)-RINSTR(OpenDialog.FileName,"\"))
     infos.Panel(0).caption="Format:"+str$(video.ImgWidth)+"*"+str$(video.ImgHeight)
     infos.Panel(1).caption="Durée:"+GetMinutes(video.LenghtTime)
     infos.Panel(2).caption=""
   else
     showmessage video.error
   end if
  end if
End Sub

Sub Close
  if flagSpeaker then
    flagSpeaker=false
    video.AudioOff=false
    btSpeaker.bmpHandle=SPEAKERBMP
  end if
  video.close
  TrackBar1.Position=0
  Item11.Enabled=false
  TrackBar1.Enabled=false
  TrackBar2.Enabled=false
  Form.width=FormWidth
  Form.Height=FormHeight
  BtStop.Enabled=false
  BtPlay.Enabled=false
  BtPause.Enabled=false
  BtSpeaker.Enabled=false
  form.caption="Vidéo"
  flagSeq=false
  infos.Panel(0).caption="Format:"
  infos.Panel(1).caption="Durée:"
  infos.Panel(2).caption=""
End Sub

Sub Play
  if video.FileOpen=false then BtStop.Down=True
  if item25.checked then
    video.close
    video.parent=form3.handle
    form3.show
    video.open(Filename)
    video.width=form3.width
    video.height=form3.height
  end if
  video.play
End Sub

Sub Stop
  video.stop
  TrackBar1.Position=0
  if item25.checked then
    video.close
    form3.close
    video.parent=form.handle
    video.open(Filename)
    if item21.checked then zoom1
    if item22.checked then zoom2
    if item23.checked then zoom3
    if item24.checked then zoom4
    BtStop.Down=True
    video.show
  end if
End Sub

Sub Pause
  if video.FileOpen=false then BtStop.Down=True
  video.pause
End Sub

Sub TrackBarChange
  video.currentFrame=TrackBar1.Position
End Sub

Sub PostimerOnTimer(Position as long,timePos as long)
  TrackBar1.Position=Position
  infos.Panel(2).caption=GetMinutes(timePos)
  If Video.State=VD_STOP and flagSeq=false then
    TrackBar1.Position=0
    BtStop.Down=True
    if item25.checked then
      video.close
      form3.close
      video.parent=form.handle
      video.open(Filename)
      if item21.checked then zoom1
      if item22.checked then zoom2
      if item23.checked then zoom3
      if item24.checked then zoom4
      video.show
    end if
  end if
  If Video.State=VD_STOP and flagSeq=true then
    TrackBar1.Position=0
    video.close
    counter=counter+1
    if (counter+1)<=listSeq.itemCount then
      if video.open(listSeq.item(counter)) then
        FileName=listSeq.item(counter)
        if item25.checked then
          video.width=form3.width
          video.height=form3.height
        else
          form.Width=video.width+(form.width-form.clientWidth)+2
          form.Height=video.height+panel1.height+(form.height-form.clientHeight)
          if item21.checked then zoom1
          if item23.checked then zoom3
          if item24.checked then zoom4
        end if
        TrackBar1.Max=video.lenght
        video.play
        form.caption="Vidéo - "+right$(listSeq.item(counter),Len(listSeq.item(counter))-RINSTR(listSeq.item(counter),"\"))
        infos.Panel(0).caption="Format:"+str$(video.ImgWidth)+"*"+str$(video.ImgHeight)
        infos.Panel(1).caption="Durée:"+GetMinutes(video.LenghtTime)
      else
        showmessage video.error
      end if
    else  
      if item25.checked then
        form3.close
        video.parent=form.handle
      end if
      BtPlay.Down=False
      BtStop.Down=True
      Close
    end if
  end if
End Sub

Sub Quitter
  video.close
  form.close
End Sub

Sub Zoom1
  if video.FileOpen then
    Item21.checked=true
    Item22.checked=false
    Item23.checked=false
    Item24.checked=false
    video.width=video.ImgWidth*(50/100)
    video.height=video.ImgHeight*(50/100)
    form.Width=video.width+(form.width-form.clientWidth)+2
    form.Height=video.height+panel1.height+(form.height-form.clientHeight)
  end if
End Sub

Sub Zoom2
  if video.FileOpen then
    Item21.checked=false
    Item22.checked=true
    Item23.checked=false
    Item24.checked=false
    video.width=video.ImgWidth*(100/100)
    video.height=video.ImgHeight*(100/100)
    form.Width=video.width+(form.width-form.clientWidth)+2
    form.Height=video.height+panel1.height+(form.height-form.clientHeight)
  end if
End Sub

Sub Zoom3
  if video.FileOpen then
    Item21.checked=false
    Item22.checked=false
    Item23.checked=true
    Item24.checked=false
    video.width=video.ImgWidth*(150/100)
    video.height=video.ImgHeight*(150/100)
    form.Width=video.width+(form.width-form.clientWidth)+2
    form.Height=video.height+panel1.height+(form.height-form.clientHeight)
  end if
End Sub

Sub Zoom4
  if video.FileOpen then
    Item21.checked=false
    Item22.checked=false
    Item23.checked=false
    Item24.checked=true
    video.width=video.ImgWidth*(200/100)
    video.height=video.ImgHeight*(200/100)
    form.Width=video.width+(form.width-form.clientWidth)+2
    form.Height=video.height+panel1.height+(form.height-form.clientHeight)
  end if
End Sub

Sub Speaker
  if flagSpeaker then
    video.AudioOff=false
    btSpeaker.bmpHandle=SPEAKERBMP
    flagSpeaker=false
  else
    video.AudioOff=true
    btSpeaker.bmpHandle=SPEAKEROFFBMP
    flagSpeaker=true
  end if
End Sub

Sub EditSeq
  Form2.showmodal
End Sub

Sub AddSeq
  If OpenDialog.Execute Then
    listSeq.additems(OpenDialog.fileName)
  end if
End Sub

Sub DelSeq
  if listSeq.itemIndex>-1 then
    listSeq.delItems(listSeq.itemIndex)
  end if
End Sub

Sub DelAllSeq
  listSeq.clear
End Sub

Sub CloseSeq
  form2.close
  if listSeq.itemCount>0 then
    item14.enabled=true
  else
    item14.enabled=false
  end if
End Sub

Sub PlaySeq
  if listSeq.itemCount>0 then
    video.close
    flagSeq=true
    counter=0
    if item25.checked then
      video.parent=form3.handle
      form3.show
    end if
    if video.open(listSeq.item(counter)) then
      FileName=listSeq.item(counter)
      if item25.checked then
        video.width=form3.width
        video.height=form3.height
      else
        form.Width=video.width+(form.width-form.clientWidth)+2
        form.Height=video.height+panel1.height+(form.height-form.clientHeight)
        if item21.checked then zoom1
        if item23.checked then zoom3
        if item24.checked then zoom4
      end if
      TrackBar1.Enabled=true
      TrackBar2.Enabled=true
      TrackBar1.Max=video.lenght
      TrackBar1.Position=0
      BtStop.Enabled=true
      BtPlay.Enabled=true
      BtPause.Enabled=true
      BtSpeaker.Enabled=true
      BtPlay.Down=True
      Item11.Enabled=true
      video.play
      form.caption="Vidéo - "+right$(listSeq.item(counter),Len(listSeq.item(counter))-RINSTR(listSeq.item(counter),"\"))
      infos.Panel(0).caption="Format:"+str$(video.ImgWidth)+"*"+str$(video.ImgHeight)
      infos.Panel(1).caption="Durée:"+GetMinutes(video.LenghtTime)
    else
      showmessage video.error
    end if
  end if
End Sub

Sub FullScreen
  if item25.checked then
    item25.checked=false
  else
    If Video.State=VD_PLAY then
      video.stop
      video.close
      video.parent=form3.handle
      form3.show
      video.open(Filename)
      video.width=form3.width
      video.height=form3.height
      video.play
    end if
    item25.checked=true
  end if
End Sub

Sub VolumeChange
  video.volume=TrackBar2.position
End Sub



Hosted by uCoz