Blitz3D+ Command Reference

DrawMovie ( movie[,x][,y][,w][,h] )

Parameters

movie - movie handle returned by OpenMovie

x (optional) - left edge to draw at; 0 (default)

y (optional) - top edge to draw at; 0 (default)

w (optional) - width to draw at; -1 uses the movie's own width (default)

h (optional) - height to draw at; -1 uses the movie's own height (default)

Description

Draws the next frame of a movie into the current buffer.

Call it once per frame from your main loop, exactly where you would call DrawImage. The frame lands in whatever buffer SetBuffer has selected, so a movie can go straight to the back buffer for a full-screen cutscene, or into an image buffer if you want to use it as a texture. Give it a width and height and the frame is scaled into that rectangle for you, which is how you letterbox a 4:3 video into a widescreen window or shrink a clip down to a TV set in the corner of a room.

The return value is the same flag MoviePlaying reports: 1 while there are frames left, 0 once the movie has reached its end. That makes While DrawMovie(movie,0,0) a complete cutscene loop on its own.

The important thing to understand is that each call advances the movie by exactly one frame. It does not look at the clock, so the video plays at whatever rate your loop runs at - fast on a quick machine, slow on a busy one. If you need real-time playback, keep your own timer and only call DrawMovie when enough milliseconds have passed for the next frame.

The frame is a plain scaled copy: no transparency, no blending, no rotation, and the movie's own sound track is not played. Passing a handle of 0 - which is what OpenMovie returns when it fails - is not checked and will take your program down, so test the handle first.

See also: OpenMovie, MoviePlaying, CloseMovie, MovieWidth, MovieHeight, SetBuffer.

Example

; DrawMovie Example
; -----------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; Copy a video file called my_movie.avi next to this .bb file to see
; this example play it - Blitz3D+ ships no video of its own.
movie_file$="my_movie.avi"

found=0
If FileType(movie_file)=1 Then found=1

Cls
Text 0,0,"DrawMovie draws the next frame of a movie into the current buffer."
Text 0,40,"Looking for "+movie_file+" in this example's folder"
If found Then
    Text 0,60,"Found it."
Else
    Text 0,60,"Not there - copy a video file in under that name to see it play."
End If
Text 0,100,"Press and hold Y to open it, or any other key to skip"
Flip

WaitKey

movie=0
If KeyDown(21) And found Then movie=OpenMovie(movie_file)

; 1 = own size, 2 = half size, 3 = stretched to fill the window
preset=1
spin#=0

While Not KeyDown(1)

    Cls

    ; Number keys pick the destination rectangle
    If KeyHit(2) Then preset=1
    If KeyHit(3) Then preset=2
    If KeyHit(4) Then preset=3

    If movie<>0 Then

        w=MovieWidth(movie)
        h=MovieHeight(movie)
        If preset=2 Then
            w=w/2
            h=h/2
        End If
        If preset=3 Then
            w=600
            h=340
        End If

        ; One frame per call. The return value is 1 while there are
        ; frames left and 0 once the movie has run out.
        playing=DrawMovie(movie,20,100,w,h)

        Text 0,40,"DrawMovie movie,20,100,"+w+","+h+"  returned "+playing
        Text 0,60,"Leave w and h out and it draws at "+MovieWidth(movie)+" x "+MovieHeight(movie)

    Else

        spin=spin+3
        Color 90,120,190
        Rect 300+Cos(spin)*70,240+Sin(spin)*70,24,24,1
        Color 255,255,255
        Text 0,40,"No movie open, so there is nothing for DrawMovie to draw."
        Text 0,60,"It needs a handle from OpenMovie - never pass it 0."

    End If

    Text 0,0,"1: own size   2: half size   3: stretch   Esc: exit"

    Flip

Wend

If movie<>0 Then CloseMovie movie

End

Index